Search code examples
rr-forestplot

Forest plot using risk ratio and confidence intervals


How to make forest plot like this using risk ratio and confidence intervals with the comparison labels? I don't want R to automatically group the comparison, I just want to plot the forest plot with the labels at the left hand side. Thank you.

I use this code:

d=result
df=data.frame(d)

cochrane_from_rmeta <- 
  structure(list(
    mean  = df$RiskRatio, 
    lower = df$LowerLimit,
    upper = df$UpperLimit),
    .Names = c("RiskRatio", "lower", "upper"), 
    row.names = c(NA, -14L), 
    class = "data.frame")

tabletext<-cbind(
  c(df$Outcomes),
  c(df$Comparison),
  c(df$...4),
  c(df$RiskRatio))

forestplot(tabletext, 
           cochrane_from_rmeta,new_page = TRUE,
           is.summary=c(TRUE,TRUE,rep(FALSE,8),TRUE),
           clip=c(0.1,2.5), 
           xlog=TRUE, 
           col=fpColors(box="royalblue",line="darkblue", summary="royalblue"))

but it shows error


Solution

  • Is this what you're trying to achieve?

    #install.packages("forestplot")
    library(forestplot)
    # Cochrane data from the 'rmeta'-package
    cochrane_from_rmeta <- 
      structure(list(
        mean  = c(NA, NA, 0.578, 0.165, 0.246, 0.700, 0.348, 0.139, 1.017, NA, 0.531), 
        lower = c(NA, NA, 0.372, 0.018, 0.072, 0.333, 0.083, 0.016, 0.365, NA, 0.386),
        upper = c(NA, NA, 0.898, 1.517, 0.833, 1.474, 1.455, 1.209, 2.831, NA, 0.731)),
        .Names = c("mean", "lower", "upper"), 
        row.names = c(NA, -11L), 
        class = "data.frame")
    
    tabletext<-cbind(
      c("", "Study", "Auckland", "Block", 
        "Doran", "Gamsu", "Morrison", "Papageorgiou", 
        "Tauesch", NA, "Summary"),
      c("",
        "Comparison",
        "Placebo 1",
        "Placebo 2",
        "Placebo 3",
        "Placebo 4",
        "Placebo 5",
        "Treatment 1",
        "Treatment 2",
        NA,
        ""),
      c("",
        "Relative Risk \n 95% CI",
        "0.88 (0.84-0.92)",
        "0.87 (0.81-0.94)",
        "0.88 (0.84-0.92)",
        "0.87 (0.81-0.94)",
        "0.88 (0.84-0.92)",
        "0.88 (0.84-0.92)",
        "0.87 (0.81-0.94)",
        NA,
        "0.87 (0.81-0.94)"),
      c("", "OR", "0.58", "0.16", 
        "0.25", "0.70", "0.35", "0.14", 
        "1.02", NA, "0.53"),
      c("", "F", "1.1", "1.3", 
        "0.2", "5", "3.1", "0", 
        "0.1", NA, "4.1"))
    
    forestplot(tabletext, 
               cochrane_from_rmeta,
               graph.pos = 3, 
               new_page = TRUE,
               is.summary=c(rep(FALSE,11)),
               clip=c(0.1,2.5), 
               xlog=TRUE,
               col=fpColors(box="royalblue",
                            line="darkblue",
                            summary="royalblue"))
    

    forestplotdemo