forestploter
forestploter copied to clipboard
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)
Sometimes, it is preferred that the reference line does not cross the summary diamond (an example below):
My question is: Can this be done in this package?
Thanks!
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.
Thank you, that would be nice!
I have updated it now and you can install it from the GitHub.
Many thanks for your help. Have a nice weekend! :)
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
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
Hi Willi,
I don't think I have ever modified the package reference line. Can you give me more details on this?
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.
Thank you!
Best wishes, Willi