1

This is for a systematic review, so I can analyse only the data that previous papers have provided. For seven such, there are enough data so that I can construct the CI, which I want to present in the usual forest plot way, including the attractive feature of sizing boxes according to the length of the CI.

For the eighth – here labelled Awkward – because the sample size is not revealed, I can only show (preferably on the same forest plot) the mean, but not a CI. So, I need help in tweaking the code below so as to present this mean as a single dot on the plot without distorting the sizes of the other seven Okay boxes.

On adding an extremely narrow CI for Awkward: either the CI is too narrow and R rounds the value resulting in no box being shown, or the CI is so narrow that the forest plot library interprets it as a "sure" thing and gives it the highest weight (so a very large box) which in turn causes all the other boxes to become indistinguishably tiny and kind of defeating the purpose. A student also looked at assigning a very large CI for Awkward--this gives Awkward a small box and keeps the other states relatively proportional, although the "whiskers" for upper and lower bounds of the Awkward OR become very long.

One way to force the desired effect in the display might be to claim a very large CI (reducing the weight) for Awkward, and print that CI line in white/transparent (so not visible); I don’t know how to do that. (I am, as you may have guessed, definitely a beginner.)

library(forestplot)

# grafted from https://cran.r-project.org/web/packages/forestplot/vignettes/forestplot.html
##According to this Awkward doesn't have a confidence interval; entries of 0.1 and 30 are fictitious
Table1_19225_OR <- 
  structure(list(
    mean  = c(NA, NA, 6, 4.19, 3.11, 3.79, 13.20, 3.84, 2.32, 5.78, NA, 4.41, 5.99, 5.43), 
    lower = c(NA, NA, 0.1, 2.54, 1.39, 1.83, 6.25, 2.69, 1.04, 2.89, NA, 3.13, 4.65, 4.79),
    upper = c(NA, NA, 30, 6.91, 6.96, 7.85, 27.87, 5.49, 5.2, 11.54, NA, 6.23, 7.71, 6.14)),
    .Names = c("mean", "lower", "upper"), 
    row.names = c(NA, -14L), 
    class = "data.frame")
#State data pooled using random effects model
tabletext<-cbind(
  c("", "State", "Awkward", "Okay1", "Okay2", "Okay3",  "Okay4", "Okay5", "Okay6", "Okay7", NA, "State data", "National", "National"),
  c("Change", "Year", "1977", "1977", "1977", "1982", "1989", "1997", "2000", "2012", NA, "", "1995-2003", "2005-2008"),
  c("Odds", "Ratio", "6.00", "4.19", "3.11", "3.89", "13.20", "3.84", "2.32", "5.78", NA, "4.41", "5.99", "5.43"))

forestplot(tabletext, 
           hrzl_lines = gpar(col="#444444"),
           Table1_19225_OR, new_page = TRUE,
           is.summary=c(TRUE,TRUE,rep(FALSE,9),TRUE,FALSE,FALSE), #TRUE means bold
           clip=c(2, 14), 
           ci.vertices = TRUE,
           xlog=FALSE, 
           xticks = c(2.0, 4.0, 6.0, 8.0, 10, 12),
           grid=TRUE,
           xlab="95% CIs for Odds Ratio",
           col=fpColors(box="royalblue",line="darkblue", summary="royalblue"))

Font size changes

own<-fpTxtGp() own #checking to see what the default values are--I think these are loaded each time you call the forestplot library own$xlab$cex <- 1.25 #default is 1, not sure what units this thing is so trial-and-error own$legend$cex <- 0.8 #default is 0.8, changing this doesn't appear to change anything on forestplot own$ticks$cex <- 0.8 #default is 0.5, changes the size of the numbers on the CI scale

4

1 回答 1

0

As you can't really know the confidence interval in your scenario I think the easiest is to simply modify the confidence interval function to handle plotting values with missing data. In the below example I check for NA in either the lower or upper and if I can't find it I plot a grid.circle instead of a grid.rect that fpDrawnormalCI uses.

library(forestplot)

fn <- function(..., 
               y.offset = 0.5,
               lower_limit, estimate, upper_limit,
               clr.marker){
  if (is.na(lower_limit) || is.na(upper_limit)) {
    grid.circle(x = unit(estimate, "native"), y = y.offset, 
                r = unit(.1, "snpc"), 
                gp = gpar(fill = clr.marker, col = clr.marker))

  } else {
    # Forward otherwise to the default function
    fpDrawNormalCI(..., 
                   y.offset = y.offset,
                   lower_limit = lower_limit, 
                   estimate = estimate,
                   upper_limit = upper_limit,
                   clr.marker = clr.marker)
  }
}

# grafted from https://cran.r-project.org/web/packages/forestplot/vignettes/forestplot.html
##According to this Awkward doesn't have a confidence interval; entries of 0.1 and 30 are fictitious
Table1_19225_OR <- 
  structure(list(
    mean  = c(NA, NA, 6, 4.19, 3.11, 3.79, 13.20, 3.84, 2.32, 5.78, NA, 4.41, 5.99, 5.43), 
    lower = c(NA, NA, NA, 2.54, 1.39, 1.83, 6.25, 2.69, 1.04, 2.89, NA, 3.13, 4.65, 4.79),
    upper = c(NA, NA, NA, 6.91, 6.96, 7.85, 27.87, 5.49, 5.2, 11.54, NA, 6.23, 7.71, 6.14)),
    .Names = c("mean", "lower", "upper"), 
    row.names = c(NA, -14L), 
    class = "data.frame")
#State data pooled using random effects model
tabletext<-cbind(
  c("", "State", "Awkward", "Okay1", "Okay2", "Okay3",  "Okay4", "Okay5", "Okay6", "Okay7", NA, "State data", "National", "National"),
  c("Change", "Year", "1977", "1977", "1977", "1982", "1989", "1997", "2000", "2012", NA, "", "1995-2003", "2005-2008"),
  c("Odds", "Ratio", "6.00", "4.19", "3.11", "3.89", "13.20", "3.84", "2.32", "5.78", NA, "4.41", "5.99", "5.43"))

forestplot(tabletext, 
           Table1_19225_OR, 
           fn.ci_norm = fn,
           hrzl_lines = gpar(col="#444444"),
           new_page = TRUE,
           is.summary=c(TRUE,TRUE,rep(FALSE,9),TRUE,FALSE,FALSE), #TRUE means bold
           clip=c(2, 14), 
           ci.vertices = TRUE,
           xlog=FALSE, 
           xticks = c(2.0, 4.0, 6.0, 8.0, 10, 12),
           grid=TRUE,
           xlab="95% CIs for Odds Ratio",
           col=fpColors(box="royalblue",line="darkblue", summary="royalblue"))

And here's the plot itself:

forestplot output

于 2019-03-24T20:45:22.330 回答