forestploter icon indicating copy to clipboard operation
forestploter copied to clipboard

Edit the length of reference line

Open willizhang opened this issue 2 years ago • 8 comments
trafficstars

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!

willizhang avatar Sep 28 '23 08:09 willizhang

Thank you for reporting this. I think the plot you sent actually cross the diamond, but the diamond is on the top of the reference line. Maybe I should change the reference line be drawn under the reference line. I will fix this. Thanks.

adayim avatar Sep 28 '23 16:09 adayim

Thank you, that would be nice!

willizhang avatar Sep 29 '23 06:09 willizhang

I have updated it now and you can install it from the GitHub.

adayim avatar Sep 30 '23 12:09 adayim

Many thanks for your help. Have a nice weekend! :)

willizhang avatar Oct 01 '23 11:10 willizhang

Hi,

Thanks for your informative video on ESMARConf2023: {forestploter} tutorial. May I ask how the codes and output were included in the slides. :)

Thanks, Willi

willizhang avatar Oct 01 '23 13:10 willizhang

Hi,

thanks for your help earlier. I notice that this issue with the length of reference line happens again. Would it be possible to help have a look at this?

Thanks, Willi

willizhang avatar Jan 15 '24 15:01 willizhang

Hi Willi,

I don't think I have ever modified the package reference line. Can you give me more details on this?

adayim avatar Jan 15 '24 20:01 adayim

Hi Alim,

I did a screenshot (see below): it shows that the reference line exceeds the diamond. Earlier, you helped resolve the issue, so that the reference line does not show below the diamond. I am using the updated version of the package.

image

Thank you!

Best wishes, Willi

willizhang avatar Jan 15 '24 20:01 willizhang