Cebs
Cebs

Reputation: 180

col and row names in a Forest plot

I don't how to introduce columns and rows names into a forest plot. Here is the dataset:

structure(list(structure(c(5L, 6L, 4L, 3L, 2L, 1L), .Label = c("Austria", 
"Denmark", "England", "France", "Portugal", "Spain"), class = "factor"), 
Slope = c(-1.8511, -2.33305, -2.698, -1.46, -0.98, -1.401
), low = c(-3.3021, -4.305, -5.873, -4.86, -5.082, -2.887
), high = c(-0.4008, -0.364, -0.087, 2.98, 3.125, -0.054), 
bS0 = c(-5.66, -2.709, -4.057, -1.224, -0.574, -1.43), Sf = c(0.354, 
0.169, 0.253, 0.077, 0.036, 0.089), `S0-Sf` = c(0.146, 0.126, 
0.169, 0.091, 0.061, 0.088)), .Names = c("", "Slope", "low", 
"high", "bS0", "Sf", "S0-Sf"), class = "data.frame", row.names = c(NA, 
-6L))

And here the script to get the Forest plot:

windows()
forestplot(labeltext=data, graph.pos=3, 
       mean=c(data$Slope), 
       lower=c(data$low), upper=c(data$high),
       xlab="Regression Coefficient",
       txt_gp=fpTxtGp(label=gpar(cex=1),
                      ticks=gpar(cex=1),
                      xlab=gpar(cex = 1),
                      title=gpar(cex = 1)),
       col=fpColors(box="black", lines="black", zero = "gray50"),
       zero=0, cex=0.9, lineheight = "auto", boxsize=0.1,
       lwd.ci=1, ci.vertices=TRUE, ci.vertices.height = 0.1,colgap=unit(4,"mm"))

And here is the outcome: enter image description here

However, I would like to introduce the names of the countries (column 1 of my data) and the columns names. How should I do it?

Upvotes: 2

Views: 1836

Answers (2)

user8941198
user8941198

Reputation: 16

You need to use graph.pos argument inside the forestplot function.

For example, use graph.position=3 if you want the plot after the slope column

Upvotes: 0

Adamm
Adamm

Reputation: 2306

I don't know how to modify you solution, so I did it my way:

data <- 
  structure(list(
    coef  = c(NA,-1.85110, -2.33305, -2.69800, -1.46000, -0.98000, -1.40100), 
    low = c(NA,-3.3021, -4.3050, -5.8730, -4.8600, -5.0820, -2.8870),
    high = c(NA,-0.4008, -0.3640, -0.0870,  2.9800,  3.1250, -0.0540)),
    .Names = c("coef", "low", "high"), 
    row.names = c(NA, -7L), 
    class = "data.frame")

tabletext<-cbind(c(NA,"Portugal","Spain","France","Engald","Denmark","Austria"),
                 c("Slope", "-1.8511", "-2.33305", "-2.698", "-1.46", "-0.98", "-1.401"),
                 c("low", "-3.3021", "-4.305", "-5.873", "-4.86", "-5.082", "-2.887"),
                 c("high", "-0.4008", "-0.364", "-0.087", "2.98", "3.125", "-0.054"),
                 c("bS0", "-5.66", "-2.709", "-4.057", "-1.224", "-0.574", "-1.43"),
                 c("Sf", "-0.354", "0.169", "0.253", "0.077", "0.036", "0.089"),
                 c("S0-Sf", "0.146", "0.126", "0.169", "0.091", "0.061", "0.088"))

forestplot(tabletext, 
           data,new_page = TRUE,
           clip=c(-6,3), 
           boxsize = .25,
           graphwidth = unit(10, "cm"),
           xlog=F, 
           col=fpColors(line="black"),
           xlab="Regression Coefficient")

enter image description here

Upvotes: 1

Related Questions