我想创建一个图,其中包含所有层的调整值(每个层的顶线)和匹配值(每个层中由 X 表示的线),例如男性、女性、年龄 <55、年龄 >55 等。对于匹配值, 我想要一个钻石/其他形状或不同的颜色来突出显示。但不知道怎么办?
我意识到我可以使用这个示例http://gforge.se/2013/12/the-forestplot-of-dreams/ 制作两个单独的数据集,一个用于调整值,一个用于匹配值,然后组合 - 但宁愿不必再次输入所有值。
有人可以帮助编辑我的代码的第三部分,以便为我的图表中的匹配值制作差异形状或差异颜色(匹配的 val 是 N 列中由 X 表示的线)。
library(forestplot)
main_acevccb <-
structure(list(
mean = c(NA, NA, NA, -1.12, -0.64, -1.55,-1.60, NA, -1.35,-1.44, -1.3, -1.2, NA, -1.29,-1.23, -2.82,-2.15, -1.84,-2.72),
lower = c(NA, NA, NA, -1.41, -0.84, -1.85, -1.86, NA, -1.71,-1.9, -1.57,-1.52, NA, -1.53, -1.54, -4.04, -3.61, -2.85,-4.45),
upper = c(NA, NA, NA, -0.83, -0.44, -1.26, -1.34, NA, -1.0, -0.98,-1.04, -0.87, NA, -1.04,-0.93, -1.59,-0.68, -0.82, -0.99)),
.Names = c("Difference", "lower", "upper"),
row.names = c(NA, -19L),
class = "data.frame")
tabletext_acevccb<-cbind(
c("", "Analysis", "", "Male", "", "Female","", "", "Aged <55yrs","", "Aged >=55yrs", "", "", "White", "", "Black", "", "South Asian", ""),
c("", "N", NA, "146,763", "X", "123,425", "X", NA, "104,584","X", "165,604", "X", NA, "258,565", "X", "4,115", "X", "5,148", "X"),
c(NA, "Diff Sys BP
CCB vs ACE/ARB", NA, "-1.12","-0.64", "-1.55", "-1.60", NA, "-1.35", "-1.44", "-1.30", "-1.20", NA, "-1.29","-1.23", "-2.82", "-2.15", "-1.84", "-2.72"),
c(NA, "95% CI", NA,"-1.41 : -0.83", "-0.84 : -0.44", "-1.85 : -1.26", "-1.86 : -1.34", NA, "-1.71 : -1.0", "-1.90 : -0.98", "-1.57 : -1.04", "-1.52 : -0.87", NA, "-1.53 : -1.04", "-1.54 : -0.93", "-4.04 : -1.59", "-3.61 : -0.68", "-2.85 : -0.82", "-4.45 : -0.99"))
forestplot(tabletext_acevccb,
main_acevccb,new_page = TRUE,
hrzl_lines=list("3" = gpar(lwd=1, col="#444444")),
is.summary=c(TRUE, TRUE, TRUE, rep(FALSE, 16)),
txt_gp = fpTxtGp(label=gpar(cex=0.7)
),
boxsize=0.25,
xlog=F,
graphwidth = unit(7.5, "cm"),
clip= c(-3.5, 0.5),
xticks=c(-3.5, -3.0, -2.5, -2.0, -1.5, -1.0, -0.5 , 0, 0.5),
col=fpColors(box="royalblue",line="darkblue"))
编辑下面是根据以下建议提供图表的代码。谢谢你提出这个建议。但是,要按照上图保持“n”、“diff”和“95% CI” - 我认为我的问题可以简化为“如何修改上面的 col=fpColors 代码以将每个框涂上不同的颜色?”
main_acevccb <- structure(list(
analysis = c( "Male","Male", "Female", "Female", NA, "<55", "<55", ">55", ">55",NA, "White", "White", "Black","Black", "SA", "SA"),
mean = c( -1.12, -0.64, -1.55,-1.60, NA, -1.35,-1.44, -1.3, -1.2, NA, -1.29,-1.23, -2.82,-2.15, -1.84,-2.72),
lower = c( -1.41, -0.84, -1.85, -1.86, NA, -1.71,-1.9, -1.57,-1.52, NA, -1.53, -1.54, -4.04, -3.61, -2.85,-4.45),
upper = c( -0.83, -0.44, -1.26, -1.34, NA, -1.0, -0.98,-1.04, -0.87, NA, -1.04,-0.93, -1.59,-0.68, -0.82, -0.99),
type = c( "adjusted", "matched","adjusted", "matched", NA, "adjusted", "matched","adjusted", "matched", NA, "adjusted", "matched","adjusted", "matched", "adjusted", "matched")),
.Names = c("Analysis","Difference", "lower", "upper", "type"),
row.names = (c(NA, -16L)),
class = "data.frame")
adjusted <- subset(main_acevccb, type!="matched"|is.na(type))
matched <- subset(main_acevccb, type!="adjusted"|is.na(type))
forestplot(mean=cbind(adjusted[,"Difference"], matched[,"Difference"]),
lower=cbind(adjusted[,"lower"], matched[,"lower"]),
upper=cbind(adjusted[,"upper"], matched[,"upper"]),
labeltext=matched$Analysis,
legend=c("Adjusted", "Matched"),
legend.pos=("bottomright"),
legend.gp = gpar(col="#AAAAAA"),
legend.r=unit(.1, "snpc"),
fn.ci_norm = c(fpDrawNormalCI, fpDrawCircleCI),
boxsize = .30,
line.margin = .5,
clip=c(-4.0, 1.0),
xticks=c(-4.0, -3.5, -3.0, -2.5, -2.0, -1.5, -1.0, -0.5, 0, 0.5, 1),
col=fpColors(box=c("darkblue", "darkred")),
xlab="Diff in Systolic BP CCB vs ACE-I/ARB",
new_page=TRUE)