adayim / forestploter

Draw forestplot in R
Other
78 stars 10 forks source link

Help modifying cell size #30

Open dianacarbg opened 1 year ago

dianacarbg commented 1 year ago

Hi! The package is great but I need some help reducing the size of each cell beacuse my forest has around 70 studies. I've tried with the forest _theme function or the gpar funcion and I can manage only to reduce the font size but not the size of the cell.

I appreciate it if you could help me!

Thanks

adayim commented 1 year ago

Hi, the cell size is determined by the contents inside cells. In other words the hight of the cell is determined by the maximum cell height of the row, width id determined by the maximum cell width of the column. The only way would be to reduce the font size. or less contents inside a cell.

TACdeVries commented 1 year ago

Hi Ayadim,

Is it possible to increase the cell size to keep them constant? I have some cells with superscripted letters or numbers which increased the height of these cells. Now the heights are inconsistent with cells without such text.

Hope this makes sense, Tim

adayim commented 1 year ago

Hi Tim,

The height and width of the plot is determined by the content. You can't define the height and width of the plot. But you can modify the height and width of each row or column with the code below:

# Assume g is your final plot
# Use this to get the heights of each row to inform the choice of the height
convertHeight(p$heights, "mm", valueOnly = TRUE) 
# Change the height with some reasonable value
g$heights <- rep(unit(10, "mm"), nrow(g)) #You can assign different value for each row if you want

For the width of the columns, you can do the following:

convertWidth(p$widths, "mm", valueOnly = TRUE)
g$widths <- rep(unit(10, "mm"), ncol(g))

Hope this helps.

TACdeVries commented 1 year ago

Hi Ayadim,

Yes, this works perfectly. Thanks again so much for your help!

Best, Tim

Laksafoss commented 1 year ago

Could control of the width / height of the gtable be added as an option to forest() or be implemented as a part of the theme?

Personally, I usually don't like the row height produced by

if (group_num > 1) {
   heights <- group_num * 0.7 * col_height + theme$tab_theme$core$padding[2]
}

So, perhaps adding something along the lines of

to forets(), which may then be used in the initial construction of the gtable gt in line 263.

adayim commented 1 year ago

@Laksafoss I'm not sure I agree with you entirely. I don't believe the method I suggested earlier is ineffective. Other functions can be used to insert rows or change the plot. Row height will be adjusted accordingly. In this case, setting height with 'forest' from the start will be obsolete. I don't want to complicate the function any further when there's an easy way out. You may easily modify the height afterwards, and padding is available in the theme function is another option. I don't see any benefit in adding this to the forest function. Nonetheless, I much appreciate your advice.