Code Monkey home page Code Monkey logo

forestploter's People

Contributors

adayim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

forestploter's Issues

How to handle missing confidence intervals?

For datasets with missing values (i.e. NA) in the low and high confidence intervals, the package reports error. Is there a way to handle such missing low or high bounds for plotting? Thanks!

How can I add a line on the top of header.

Firstly, thanks for your dedication in forest plot with r.

Context

I plot a forestplot and want to add three line to make the figure looks like a three-line table.

I can add two lines by using add_underline().

Question

How can I add a line on the top of header.

Reproducible code

library(forestploter)
dt <- read.csv(system.file("extdata", "example_data.csv", package = "forestploter"))
dt <- dt[1:6,1:6]

dt$` ` <- paste(rep(" ", 20), collapse = " ")

p <- forest(dt[,c(1:3, 7)],
            est = dt$est,
            lower = dt$low,
            upper = dt$hi,
            ci_column = 4)

g <- add_underline(p, part = 'header')
g <- add_underline(g, row = 6, part = 'body')

g

The current picture looks like this. It is missing a line on the top side of the header.

image

How to use subscript in header?

Context

Hi, adayim. I want to show PM2.5 in the header.

I have tried some syntax such as $PM_{2.5}$ , $PM~2.5~$ and expression('PM'[2.5]), but all faild.

Question

How can I use subscript in header with forestploter?

Reproducible code

library(forestploter)
dt <- read.csv(system.file("extdata", "example_data.csv", package = "forestploter"))
dt <- dt[1:6,1:6]

dt$`$PM_{2.5}$` <- paste(rep(" ", 20), collapse = " ")
# dt$`$PM~2.5~$` <- paste(rep(" ", 20), collapse = " ")
# dt$`expression('PM'[2.5])` <- paste(rep(" ", 20), collapse = " ")

p <- forest(dt[,c(1:3, 7)],
            est = dt$est,
            lower = dt$low,
            upper = dt$hi,
            ci_column = 4)
p

image

How to change the line width and the style of CI?

Thank you very much for providing us with this elegant package for forest plot visualization. Although we coudl use edit_plot function to edit some elements of the figure, there is a problem when i used this function.
I want to add short vertical bar at the begining and the ending of the CI line. Although there is lineend paremeter, it seems that it dosen't work when i added this parameter in edit_plot function bu using the following code:
edit_plot(p, row = c(1, 3, 4), gp=gpar(col="red",lwd=3,lineend="round")).
I also tried to change the line with of these CI lines. However, it failed again. So, i would like to appreciate it if you could solve this problem. Thank you again for your contribution. We are looking forward to hearing more excellent funtions of this package.

Would it be possible to remove the legend?

Hi Adayim,
Thanks for this great package. It seems the legend is always present when create a forest plot with CIs by groups. I'm wondering whether the group legend can be removed, because I'd like to combine more than two forest plots with a shared legend.

Thanks a lot,
Yufeng

Aligning xlab

Hi,

Thank you so much for an excellent package.

I have a question regarding the alignment of the xlab. I have managed to create the following forestplot, but I would like the xlab to be center aligned. Is that possible at the moment? - Also, is it possible to adjust the font size just for the xlab?

billede

The data and code used to produce the plot is the following:

tribble(~term, ~estimate, ~std.error, ~statistic, ~p.value, ~n_mv, ~nevents_mv, ~hz, ~hz_str, ~lower, ~upper, ~lower_str, ~upper_str, ~estimate_str, ~ " ", ~  "  " , ~mv_hz, ~mv_lower, ~mv_upper, ~mv_estimate_str,
'leukocyt_log_scaled', 0.06, 0.02, 2.46, 0.01, 102438, 1627, 1.06, '1.06', 1.01, 1.11, '1.01', '1.11', '1.06 (1.01 - 1.11)', '                                        ', '                                        ', 1.03, 0.98, 1.08, '1.03 (0.98 - 1.08)',
'bas_diff_log_scaled', 0.03, 0.02, 2.12, 0.03, 102434, 1627, 1.04, '1.04', 1, 1.07, '1.00', '1.07', '1.04 (1.00 - 1.07)', '                                        ', '                                        ', 1.03, 1, 1.07, '1.03 (1.00 - 1.07)',
'eos_diff_log_scaled', 0.01, 0.02, 0.58, 0.56, 102414, 1626, 1.01, '1.01', 0.97, 1.06, '0.97', '1.06', '1.01 (0.97 - 1.06)', '                                        ', '                                        ', 1, 0.96, 1.05, '1.00 (0.96 - 1.05)',
'lym_diff_log_scaled', 0.03, 0.02, 1.22, 0.22, 102417, 1626, 1.03, '1.03', 0.98, 1.07, '0.98', '1.07', '1.03 (0.98 - 1.07)', '                                        ', '                                        ', 1.01, 0.96, 1.05, '1.01 (0.96 - 1.05)',
'mon_diff_log_scaled', 0.06, 0.02, 2.64, 0.01, 102415, 1626, 1.06, '1.06', 1.02, 1.11, '1.02', '1.11', '1.06 (1.02 - 1.11)', '                                        ', '                                        ', 1.05, 1, 1.1, '1.05 (1.00 - 1.10)',
'neu_diff_log_scaled', 0.06, 0.03, 2.35, 0.02, 102026, 1614, 1.06, '1.06', 1.01, 1.12, '1.01', '1.12', '1.06 (1.01 - 1.12)', '                                        ', '                                        ', 1.03, 0.98, 1.09, '1.03 (0.98 - 1.09)')
tm <- forest_theme(core = list(
    bg_params = list(fill = c("#ffffff"))
))

ticks <- seq(from = 0.95, to = 1.15, by = 0.1)  %>%  c(., 1)  %>%  sort()


fp <- fp_data %>%
    select(term, n_mv, nevents_mv, estimate_str, " ", mv_estimate_str, "  ") %>%
    rename(
        "Cell type" = term,
        "Hazard Ratio \n(95% CI)" = estimate_str,
        "Hazard Ratio \n(95% CI) " = mv_estimate_str,
        "Individuals, \nNo." = n_mv,
        "Events, \nNo." = nevents_mv
    ) %>%
    forest(
        est = list(fp_data$hz, fp_data$mv_hz),
        lower = list(fp_data$lower, fp_data$mv_lower),
        upper = list(fp_data$upper, fp_data$mv_upper),
        sizes = 0.75,
        ci_column = c(5, 7),
        ref_line = 1,
        xlim = c(0.95, 1.15),
        x_trans = "log",
        ticks_at = ticks,
        theme = tm,
        xlab = "Hazard ratio (95% CI)"
    ) %>%
    insert_text(
        text = " Model 1\n(age- and sex-adjusted)",
        part = "header",
        col = 4,
        gp = grid::gpar(fontface = "bold"),
        just = "left"
    ) %>%
    add_text(
        text = " Model 2\n(multivariable adjusted)",
        part = "header",
        row = 1,
        col = 6,
        gp = grid::gpar(fontface = "bold"), just = "left"
    ) %>%
    add_border(
        part = "header",
        row = 2,
        col = 1:4,
        gp = grid::gpar(lwd = .5)
    )

Thank you!

Negative estimates and CIs

Hi there,

First of all - thanks for this great package! Really useful and smooth to use

I'm using this to plot Cohen's Kappa statistics along with confidence intervals. Contrary to rates, Kappa's can be negative, and I have adjusted xlim to accomodate this, but am getting the following error:

The confidence interval of row 20, column 13, group 1 is outside of the xlim.
The confidence interval of row 21, column 13, group 1 is outside of the xlim.

and the corresponding dots and CIs are not plotted

Having had a look through the forest function code, it seems the issue is arising from this condition here, which could treat negative numbers as character rather than numeric values

      if upper[[col_num]][i] < min(xlim[[col_indx[col_num]]]) | 
        lower[[col_num]][i] > max(xlim[[col_indx[col_num]]])) {
        message("The confidence interval of row ", i, 
          ", column ", current_col, ", group ", current_gp, 
          " is outside of the xlim.")
        next
      }

I've tried fixing this by including by wrapping upper[[col_num]][i] in as.numeric() but get the following error:

Error in if (as.numeric(upper[[col_num]][i]) < min(xlim[[col_indx[col_num]]]) | :
missing value where TRUE/FALSE needed

Is this something you could help with? Apologies I couldn't fix it myself

Thank you

specify rows for vert_line argument

Hi, I am trying to plot a forest plot for different subgroups therefore want to show different vertical lines for different subgroup rows. Is there a way that I could specify rows for a particular vertical line to appear. e.g. vert_line[1] to appear on row 3 to row 5?

X axis break

Hi, thanks for providing this excellent package, which works very well. I have a problem. I have get some results which were ranged from 2 to 20 and I didn't find the method for x axis breaking. For example, I wanner make a gap between 5 to 15, so that I can show all results in one graph. Could you help me to complish it? Thanks so much!

Break the axes

Dear author:

Thanks for your excellent R package that solved the problem of my lazy friend who do not wanna write code.

There is a problem in drawing: sometimes a CI lines is too long for other data to be presented better.

1685418138084

Could you please add a parameter for breaking the axes or do you have any good suggestions?

And i hope that the p-values will be presented in the current graph in the future versions of this Rpkg.

Thanks again

Is it possible to overlap forest plots (plotting two sets of variables within a single column)

I am performing a meta-analysis using a meta-analytic method that allows for the inclusion of different combinations of values. One of such combinations is the median with min, Q1, Q3, and max values of a single distribution. I would have hoped to present those values graphically within a single column of the forest plot.

Is this within the range of possibilities? I was aiming for something along the lines of this (https://www.metafor-project.org/doku.php/plots:forest_plot_with_multiple_cis), but the metafor package is by not flexible enough for my other purposes (e.g., presenting two forest plots within a single figure).

Below a picture of what I am aiming for:
image

I’ve tried playing around with the est, lower, upper, and ci_column variables, but I keep getting error messages. If I change the column identifier of one of the two overlapping variables sets to a non-forest plot column, I am able to plot three forest plots within a single plot, however.

Any ideas?

Kind regards,
Tim

How do I change these TEXT fontsize

image
image

I know these can be edited in theme function ,but I don't know what these called, how do i set the parameters instead changing it in my PDF editor.

Thanks for your help.

unable to load the forestplot

a problem here.As is shown in the image,the entire interface is blank,failing to load the forestplot.I am wondering if there is any way to fix this,thanks.
Snipaste_2023-12-04_00-54-30

Argument 'background' misspelled in add_grob function

Hello,

I thought I would let you know that in line 89 of the add_grob function, the word 'background' is misspelled as 'backgroud'. This caused me some issues, it might do the same to other people, but appears to be an easy fix, so I thought you should know.

Great package otherwise!

Thanks

decimal places of the x-axis ticks

would it be possible to adapt the function make_xaxis in such a way, that the number of decimal places is not fixed to 1?
In our case the point estimates were between 0.9 and 1. The forestplot x-axis was only showing 0.9 and 1 and no tick-labes in between. We believe this will allow more flexibility and a wider use.

make_xaxis <- function(at, xlab = NULL, x0 = 1, is_exp = FALSE, gp = gpar(), xlim){

  if(is_exp){
    label_at <- log(round(exp(at), **2**))
    x0 <- log(x0)
    labels <- as.character(round(exp(at), **2**))
  }else {
    label_at <- round(at, **2**)
    labels <- as.character(round(at, **2**))
  }
.....
}

x-axis

Extend functionality for multiple plot columns

First off, thank you for making this package. This is the best forest plot package I've come across by far and it has excellent functionality and customizability. I have a couple of questions/requests regarding making plots with multiple plot columns.

Different ticks_digits for different plot columns

I believe earlier versions of this package supported users passing a vector to the ticks_digits parameter if they wished to have this parameter vary across different plot columns. I think having this feature could be useful if the two plot column estimates are on very different scales. Now when a vector is passed, you get the following error:

Error in if (ticks_digits == 1L & !is.null(ticks_at)) { : 
  the condition has length > 1

stemming from line 121 of forest.R

Vary theme parameters across plot columns

I also think it would be useful to vary theme parameter such as ci_pch, ci_col across plot columns. Currently, if you provide two estimate vectors and specify two plot columns, then you cannot adjust the theme to, for example, make confidence intervals from plot column 1 green, and those in plot column 2 red (i.e. ci_col = c("green", "red"). I don't believe any of the theme parameters support this type of input actually. It seems that this is because with two estimate vectors and two plot columns, the package determines there to be only one "group."

How can I make a specified column display with superscripts or subscripts?

For example, when I am plotting a forest plot, if one of the study subjects has a subscript like PM2.5, how can I make the 2.5 display as a subscript?

When I was drawing a forest plot, there was a column of numbers that I needed to express in scientific notation with superscripts. I found that the expression() function can be used to add superscripts when plotting graphs, for example:

library("lattice") 
y <- x <- 1:10
xyplot(y ~ x, main = expression(paste("Title ", 10^2, " abcd")))

image

I wanted to use the expression() function on a specified column when drawing the forest plot, so that the plot could display properly with superscripts or subscripts. Please advise how I can write this code.

Sizes option

Hi, thanks for this really useful package, I'm still quite new to R so please forgive me if this is simpler than I've realised...
I'd be really grateful for your advice on how to manipulate the sizes argument beyond the suggested eg. sizes=0.4 or sizes = data$se in the documentation.
I've created a forest plot for a subgroup analysis and want to scale the squares to the number of participants within each subgroup, for each subgroup, rather than across the whole plot
I've tried using sizes=data$total_participants where total_participants is the number of participants for each plotted estimate, I've tried using sizes=data$proportion where proportion is the % of participants for that category of the subgroup
I've also tried a more manual approach using a vector eg. sizes=c(0.63,0.31....) and in different forms *100 etc

The format of the data I'm using to create the plot is attached
image

And the code I'm using:

forest(data[,c(1:3, 9:11)],
est = data$hr,
lower = data$lower,
upper = data$upper,
sizes=data$total_participants,
ci_column = 4,
xlim = c(0, 3),
ticks_at = c(0,1,2,3),
ref_line = 1.0,
is_summary = c(FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,TRUE),
vert_line = 0.91,
theme=my_theme)

Thank you, very grateful for any help!

Multiple CIs in one cell

Hello!

I would like to plot multiple CIs on top of each other in the same cell (i.e. same column), represented by different colours & shown in legends.

I am currently aiming for 5 CIs, so I wrote something like this:
tm <- forest_theme(base_size = 10,
refline_col = "red",
legend_name = "5 groups",
legend_value = c(1:5)) # I want to plot 5 groups

p <- forest(dt[,c(2,22)],
est = list(dt$est_gp1,
dt$est_gp2,
dt$est_gp3,
dt$est_gp4,
dt$est_gp5),
lower = list(dt$low_gp1,
dt$low_gp2,
dt$low_gp3,
dt$low_gp4,
dt$low_gp5),
upper = list(dt$hi_gp1,
dt$hi_gp2,
dt$hi_gp3,
dt$hi_gp4,
dt$hi_gp5),
ci_column = c(3), # because I want them all in the same column
ref_line = 1,
theme = tm)

However, there was a bug which made some CIs misaligned with the rows (see picture: from "hypertension" in row 6). I have double-checked and I can confirm that the dataframe used for plotting is correctly aligned.

Also, do you know how to add p-values as asterisks to the plot please?

I am trying to make a plot like this.

Thanks!
Screenshot 2023-01-30 at 19 45 46
Screenshot 2023-01-30 at 20 33 52

How to plot points/whiskers different colors on the same plot?

Hi there! I would like to color certain rows of my plot different colors- the edit_plot() function allows me to do this for the text in the row (i.e. edit_plot(fp, row = c(3, 7, 8, 9, 11), gp = gpar(col = "red", fill = "red")), but I need the points to also be the corresponding color (red, in this example). Is there any way to achieve this? Here is an example of a plot I made (I need the points and whiskers to also be red on the corresponding rows)
image

Multiple CI columns

Hi, in your package you describe If the length of the list is larger than then length of ci_column, then the values reused for each column and considered as different groups. So I set the length of the list same as length of ci_column to make four CI columns(don't want one ci_column having two group, just one column one CI), but it occur error. Do you support this plotting?
Here is the code

dt <- read.csv(system.file("extdata", "example_data.csv", package = "forestploter"))
dt$`a outcome` <- paste(rep(" ", 20), collapse = " ")
dt$`b outcome` <- paste(rep(" ", 20), collapse = " ")
dt$`c outcome` <- paste(rep(" ", 20), collapse = " ")
dt$`d outcome` <- paste(rep(" ", 20), collapse = " ")

forest(dt[,c(1:3, 19:22)],
       est = list(dt$est_gp1,
                  dt$est_gp2,
                  dt$est_gp3,
                  dt$est_gp4),
       lower = list(dt$low_gp1,
                    dt$low_gp2,
                    dt$low_gp3,
                    dt$low_gp4), 
       upper = list(dt$hi_gp1,
                    dt$hi_gp2,
                    dt$hi_gp3,
                    dt$hi_gp4),
       ci_column = c(4,5,6,7),
       ref_line = 1,
       vert_line = c(0.5, 2),
       nudge_y = 0.2)
Error in xlim[[idx]] : subscript out of bounds

How to change the appearance of text per column ?

I have read the Introduction to forestploter, but there is something I can't figure out, so I would like to ask a question.

As shown in the attached table, I want to align each cell in the subgroup columm to the left. I want to center all other cells in the column.

forest

I tried to adjust it with core = , but I could change it per row, but not per column.
I also tried edit_plot() to change the text color per column, but not the alignment. (I tried using just =)

If there is a way to do this, I would appreciate it.

Allow summary rows when plotting multiple CI columns

Hi,

First, congrats for your package! I think it does indeed succeed in terms of flexibility and ease of use.

I'd like to see summary rows implemented when plotting multiple CI columns. I might attempt implementing it myself, although I'm not sure I'm really up to the task. I thought about just attempting to hack theme parameters as a 1st attempt.

Would you have any advice on where to begin for implementing such a feature?

Cheers!

Grouped forestplot - order groups and assign diamonds to overall estimate

Hi there,

I'm using forestploter to depict mortality estimates across time periods for three different groups. Is it possible to manually set the order in which the groups are plotted, and to have diamond shapes in the overall estimates? From reading the vignette it doesn't seem like it but I thought I'd ask. Thanks

x axis ticks: wrong value and collision

For some inputs, the forest function adds erroneous/duplicate values. See the MRE below:

in2=data.frame(effect=-0.08, lci_effect=-0.15, uci_effect=-0.03)
input=data.frame(Exposure="analysis name", Outcome="outcome name", `Beta (95% CI), Clinical Units`="confidence interval", `custom field`="custom field", prop="prop", ` `="                                                               ", P=0.3455)
forestploter::forest(input, est = in2$effect, lower = in2$lci_effect, upper = in2$uci_effect, sizes = 1, ci_column = 6, ref_line = 0, xlab = "x axis title, quite long")

image

This produces an x axis with a duplicated -0.1 value. This becomes obvious if you uncomment the check.overlap=TRUE, line in make_xaxis, you just seee two -0.1 ticks. I think what is plotted above it is the correct "0" x coordinate of the ref_line.

This may be an entirely separate issue but I am also posting here for completeness: In some other cases (no MRE for this as I saw it only in passing), it seems the x axis is plotted twice, you can clearly see the characteristic thickened effect and slight offset of the two lines being drawn over each other.

Help modifying cell size

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

Is there any way to add superscript to the header text?

Hi there,

Thank you for your great work on forest plot. I am wondering if it's possible to add superscript to the header text and make some text to be italic and others keeping unchanged, which is really important for publication. Such as "P valuea".

Thank you very much!

Improvements

Planning functionalities:

  • Able log odds options.
  • Able to add titles on the top
  • Able to add x-axis title
  • add_text accept text vector
  • Different xlim for different group

Axis labels for X-axis not displaying

Hi,
in certain instances of plotting, with custom x-ticks, the x-axis is not displaying. I tried altering the axis range without any luck. It seems to be happening when I choose axes limits with decimals.

Example code:

min_tick_custom <- -0.05
max_tick_custom <- 0.02
center_tick <- 0

p_qt <- forestploter::forest(cbind(dat[,c("Area","Phenotype","Cohorts", "Cases")],
=paste(rep(" ", 1), collapse = " "),
=paste(rep(" ", 18), collapse = " "),
dat[,c("Effect (95% CI)", "Pval", "AAF")]),
est = dat$Effect,
lower = dat$LCI_Effect,
upper = dat$UCI_Effect,
ci_column = c(6),
ref_line = center_tick,
xlim = c(min_tick_custom_qt,max_tick_custom_qt),
ticks_at = c(min_tick_custom, center_tic,max_tick_custom),
footnote=unique(plot_name),
theme=forestploter::forest_theme(base_size = 10,
base_family = 'sans',
ci_col = c("black"),
ci_pch = 16,
ci_Theight = 0.3,
xaxis_cex=0.8,
refline_col='red',
footnote_col = "#636363",
footnote_fontface = "italic"))

plot(p_qt)

Show P-values

Hi there,

Thank you for your great work.
I wonder if it's possible to add a column to the graph, showing the P values for each variable?

Thanks!

how to save as a pdf file which could change the size of picture when set different width and height?

Hi Adayim!

Thank you for developed such an excellent package, which makes it easy to draw a forestplot. When I export the figures, something happened which make the exported figures just as a fixed size. But i want save it use different width and height in pdf() function ot use ggsave() function. Now, i set different width and height make no changes for the export figures. What should i do to solve this problem?
my code :

pdf('Figure1_CKD risk factors.pdf',width = 8,height = 5)
print(a)
dev.off()

my figure:
1661654311520

Thank you again for this great package and have a nice day!

Add ticks but not show labels at the ticks

Hi, I would like to ask if it would be possible to add ticks to x-axis but not show labels. for example:

library(grid)
library(forestploter)

dt <- read.csv(system.file("extdata", "example_data.csv", package = "forestploter"))

# indent the subgroup if there is a number in the placebo column
dt$Subgroup <- ifelse(is.na(dt$Placebo), 
                      dt$Subgroup,
                      paste0("   ", dt$Subgroup))

# NA to blank
dt$Treatment <- ifelse(is.na(dt$Treatment), "", dt$Treatment)
dt$Placebo <- ifelse(is.na(dt$Placebo), "", dt$Placebo)
dt$se <- (log(dt$hi) - log(dt$est))/1.96

# Add blank column for the forest plot to display CI.
# Adjust the column width with space. 
dt$` ` <- paste(rep(" ", 20), collapse = " ")

# Create confidence interval column to display
dt$`HR (95% CI)` <- ifelse(is.na(dt$se), "",
                           sprintf("%.2f (%.2f to %.2f)",
                                   dt$est, dt$low, dt$hi))

# Define theme
tm <- forest_theme(base_size = 10,
                   refline_col = "red",
                   arrow_type = "closed",
                   footnote_col = "blue")

p <- forest(dt[,c(1:3, 20:21)],
            est = dt$est,
            lower = dt$low, 
            upper = dt$hi,
            sizes = dt$se,
            ci_column = 4,
            ref_line = 1.11,
            arrow_lab = c("Placebo Better", "Treatment Better"),
            is_summary = c( rep( FALSE, nrow( dt ) - 1 ), TRUE ),
            xlim = c(0, 5),
            ticks_at = c(0, 1, 2, 3, 4, 5),
            footnote = "This is the demo data. Please feel free to change\nanything you want.",
            theme = tm)

# Print plot
plot(p)
image

Sometimes, the x-axis limit can be quite long. It would be helpful to be able to add some ticks but not show all the labels.

Thank you very much in advance for your help. :)

Edit the length of reference line

Hi Alimu,

Thank you very much for this beautiful package (I am a big fan of forest plot). :) I have a question about if it would be possible to edit the length of reference line. Here is an example from your previous blog:

library(grid)
library(forestploter)

dt <- read.csv(system.file("extdata", "example_data.csv", package = "forestploter"))

# indent the subgroup if there is a number in the placebo column
dt$Subgroup <- ifelse(is.na(dt$Placebo), 
                      dt$Subgroup,
                      paste0("   ", dt$Subgroup))

# NA to blank
dt$Treatment <- ifelse(is.na(dt$Treatment), "", dt$Treatment)
dt$Placebo <- ifelse(is.na(dt$Placebo), "", dt$Placebo)
dt$se <- (log(dt$hi) - log(dt$est))/1.96

# Add blank column for the forest plot to display CI.
# Adjust the column width with space. 
dt$` ` <- paste(rep(" ", 20), collapse = " ")

# Create confidence interval column to display
dt$`HR (95% CI)` <- ifelse(is.na(dt$se), "",
                           sprintf("%.2f (%.2f to %.2f)",
                                   dt$est, dt$low, dt$hi))

# Define theme
tm <- forest_theme(base_size = 10,
                   refline_col = "red",
                   arrow_type = "closed",
                   footnote_col = "blue")

p <- forest(dt[,c(1:3, 20:21)],
            est = dt$est,
            lower = dt$low, 
            upper = dt$hi,
            sizes = dt$se,
            ci_column = 4,
            ref_line = 1.11,
            arrow_lab = c("Placebo Better", "Treatment Better"),
            xlim = c(0, 4),
            is_summary = c( rep( FALSE, nrow( dt ) - 1 ), TRUE ),
            ticks_at = c(0.5, 1, 2, 3),
            footnote = "This is the demo data. Please feel free to change\nanything you want.",
            theme = tm)

# Print plot
plot(p)
image

Sometimes, it is preferred that the reference line does not cross the summary diamond (an example below):
image

My question is:
Can this be done in this package?

Thanks!

Group multiple meta-analyses in one plot?

Hi,

First of all, thank you very much for this package, it is very intuitive and the result is excellent.

What I would like to say is that a few months ago I used the foresploter package for some research I was doing in which I needed to plot two dimensions of data. I had to plot 4 meta-analyses of depression according to the severity status of relatives who suffered from covid in 4 cohorts (see image). (here is the DOI of the preprint in case you want to see it 10.1101/2023.02.28.23286559)

model_1_hosp_phq9

At that time like June 2022, with version '0.1.6'. I was able to modify the aesthetic in this way:

prueba2<-forest(forest_dat_model1_phq9_hosp_alt[,c(1,6,7)],
       est = forest_dat_model1_phq9_hosp_alt$PR,
       lower = forest_dat_model1_phq9_hosp_alt$conf.low, 
       upper = forest_dat_model1_phq9_hosp_alt$conf.high,
       sizes = as.numeric(forest_dat_model1_phq9_hosp_alt$std.error),
       ci_column = 2,
       arrow_lab = c("less", "more"),
       xlim = c(0.8, 3),
       ticks_at = c(0.8, 1, 1.5, 2, 3), 
       is_summary = c(rep(FALSE, nrow(forest_dat_model1_phq9_hosp_alt)-4), rep(TRUE,4)),
       ref_line = 1,
       theme = tm)

z<-prueba2$grobs

#iceland
z[[134]]$children[[1]]$gp$col<-"#B0A565"
z[[134]]$children[[2]]$gp$col<-"#B0A565"

z[[135]]$children[[1]]$gp$col<-"#FF7844"
z[[135]]$children[[2]]$gp$col<-"#FF7844"

z[[136]]$children[[1]]$gp$col<-"#E14594"
z[[136]]$children[[2]]$gp$col<-"#E14594"

#map
z[[138]]$children[[1]]$gp$col<-"#B0A565"
z[[138]]$children[[2]]$gp$col<-"#B0A565"

z[[139]]$children[[1]]$gp$col<-"#FF7844"
z[[139]]$children[[2]]$gp$col<-"#FF7844"

z[[140]]$children[[1]]$gp$col<-"#E14594"
z[[140]]$children[[2]]$gp$col<-"#E14594"

z[[141]]$children[[1]]$gp$col<-"#2F86A6"
z[[141]]$children[[2]]$gp$col<-"#2F86A6"

#sct
z[[143]]$children[[1]]$gp$col<-"#2F86A6"
z[[143]]$children[[2]]$gp$col<-"#2F86A6"

#swe

z[[145]]$children[[1]]$gp$col<-"#B0A565"
z[[145]]$children[[2]]$gp$col<-"#B0A565"

z[[146]]$children[[1]]$gp$col<-"#FF7844"
z[[146]]$children[[2]]$gp$col<-"#FF7844"

z[[147]]$children[[1]]$gp$col<-"#E14594"
z[[147]]$children[[2]]$gp$col<-"#E14594"

z[[148]]$children[[1]]$gp$col<-"#2F86A6"
z[[148]]$children[[2]]$gp$col<-"#2F86A6"

#overall
z[[150]]$gp$col<-"#B0A565"
z[[150]]$gp$fill<-"#B0A565"

z[[151]]$gp$col<-"#FF7844"
z[[151]]$gp$fill<-"#FF7844"

z[[152]]$gp$col<-"#E14594"
z[[152]]$gp$fill<-"#E14594"

z[[153]]$gp$col<-"#2F86A6"
z[[153]]$gp$fill<-"#2F86A6"



prueba2$grobs<-z
prueba2<-edit_plot(prueba2, row = c(1,3,5,7,9,11,13,15,17,19,21), which = "background",
                   gp = gpar(fill = "white"))

prueba2$grobs[[1]]$label<-"Cohort (ref. Relative not infected)"

ggsave(filename = "./images_metanalysis/model_1_hosp_phq9.jpg", plot = prueba2,dpi = 800,
       width = 8, height = 6, units = "in")

However, even if I use version 0.1.6 and it works perfectly, in current versions it can no longer be done. I'm simply writing here to ask if there is any way in later versions to be able to do this type of graph (since I don't have much knowledge of grob) and if not, have you thought about implementing it in the package or in the guide an easier way to be able to make this type of groups in the graph?

Thank you very much!!

Best,
Juan

Issue with choosing the row numbers in forest function

Hi!
Thank you for this amazing package.

There was an issue I encountered when I wanted to choose the rows I wanted to visualize. When you try to change the order of the rows, choose rows that are not consecutive and or not starting from 1 you will get different types of false results. Sometimes the plot for the last row will disappear and sometimes no matter what row you put in, you will get the results for the first row of your data and sometimes everything will be just misplaced.

For what I wanted to do, there was an easy fix which was only keeping the rows I wanted to work with from the beginning. But if I wanted to change the order of the rows, I would have a problem.

Just thought maybe it was worth reporting.

`p <- forest(dt[2:7,c(1:3, 20:21)],
            est = dt$est,
            lower = dt$low, 
            upper = dt$hi,
            sizes = dt$se,
            ci_column = 4,
            ref_line = 1,
            arrow_lab = c("Placebo Better", "Treatment Better"),
            xlim = c(0, 4),
            ticks_at = c(0.5, 1, 2, 3),
            footnote = "This is the demo data. Please feel free to change\nanything you want.",
            theme = tm)`

Rplot

Recommended calculation to determine box sizes of point estimates

Dear Adayim/all,

Is there a recommended formula to determine the box sizes of the point estimates based on weights as used in meta-analytic models?

My best attempt so far is dividing the weight (in %) by 10 and taking the square root hereof. This results in values roughly between 0.5 and 1.5 and looks reasonable while still being proportional to the study weight. However, I don't want to give the wrong impression and would prefer a 'standard' method.

Does anyone know what the 'usual' formula is to determine the size? Or are there other suggestions to determine the box sizes based on weight?

Thanks,
Tim

Sizes no longer accepting a numeric vector

Hello,

Thanks so much for making this package, it has been very helpful to me! I have been using it over the past couple of months and have recently started using the sizes variable in forest(), similarly to how the guide recommends, with dt$se for example.
However, today it has stopped accepting that, for instance if sizes was initially a vector such as c(1, NA, 0.17, 0.72), on the forest plot only the first dt$est value is scaled to the correct size, but all other dt$est values have disappeared from the plot completely, leaving just the confidence interval! This is new and yesterday all dt$est values on the forest plot were scaled by the appropriate amounts.
I updated all my packages on RStudio today but as far as I'm aware that's the only change I've made. I'm not very experienced with R so apologies if it is something basic, I just can't explain it!
The dt$est values return if I comment out the whole of the sizes variale, and are still there if I specify sizes to be a single value.

Thanks in advance!

How to change the default background color?

Thank you for this great work to help us draw beautiful forest plots.
Is it possible to provide an argument to change the default background color?
image

Thank you very much !

Wrap text for header

Hi, great package, very impressed!

I have a long header name for a column, "P value for Interaction term".

Is there a way to wrap the text for the column header i.e.
"P value
for Interaction"

How to change legend size?

I want to change the size of the legend, but I found that there is no relevant code in the introduction:forest_theme.

Multiple summary diamond shapes for multiple CI columns

Hi Alimu,

I wonder if you could add a new feature where we can add multiple summary diamond shapes for multiple CI columns. The "is_summary" argument is currently not valid for multiple groups. In many cases, it seems better for me to combine some similar forest plots into one.

double zero

Double zeros in the x-ticks were found in the plot after updated for 0.1.9 and 0.2.0 version.

And when you set ticks_at = c(-0.1, -0.05, 0, 0.05, 0.1, 0.15), some of the ticks like 0.05 will be missing from the plot.

Adjusting line ends of confidence intervals?

Dear Adayim,

Is is possible to adjust the line end of the confidence intervals? The standard seems to be 'round' but I'd prefer using either 'butt' or 'square'. See this stackoverflow weblink or this picture below for more information. I can't find the option in 'forest_theme' to adjust this graphical parameter. It can't seem to be find a possibility to adjust this directly in the forest function.

image.

My apologies for the frequent requests these last couple of days.

Thanks,
Tim

Edit Column Headers

Hello;

I'm trying to use the edit_plot function to edit the column headers, but I'm having trouble getting it to work. Is there a way to change the justification of the column headers?

g <- edit_plot(g, col = c(3,5), part = "header", which = "text", gp = gpar(fontface = "italic", just= "left"))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.