森林情节中的传说

时间:2015-12-14 11:13:03

标签: r plot legend forestplot

我在R中的森林情节包中遇到了困难。这是我的代码。实际上除了传说之外,一切都很好。 Here is the forest plot I am generating with my code。然而对于传说,我想要一个蓝色圆圈,一个红色正方形和一个绿色的洛杉矶而不是3个正方形。

有什么想法吗? 提前致谢。 彼得

library(forestplot)
test_data <- data.frame(coef1=c(0.54,0.72,0.57),
                        coef2=c(0.59,0.79,0.58),
                        coef3=c(0.49,0.60,0.48),
                        low1=c(0.41,0.46,0.42),
                        low2=c(0.44,0.49,0.42),
                        low3=c(0.37,0.37,0.35),
                        high1=c(0.72,1.12,0.77),
                        high2=c(0.78,1.26,0.80),
                        high3=c(0.65,0.99,0.66))

col_no <- grep("coef", colnames(test_data))
row_names <- list(
  list("Behavioral CVH","Biological CVH","Total CVH"))

coef <- with(test_data, cbind(coef1, coef2, coef3))
low <- with(test_data, cbind(low1, low2, low3))
high <- with(test_data, cbind(high1, high2, high3))
forestplot(row_names, coef, low, high,
           title="Paris Prospective Study 3",
           fn.ci_norm=matrix(c("fpDrawCircleCI",  "fpDrawNormalCI","fpDrawDiamondCI"), 
                             nrow = 3, ncol=3, byrow=T),
           zero = c(1), boxsize=0.05,
           col=fpColors(box=c("royalblue", "gold", "black"),
                        line=c("darkblue", "orange", "black"),
                        summary=c("darkblue", "red", "black"),
                        hrz_lines = "#444444"),
           xlab="Odds ratio & 95% Confidence intervals",
           vertices = TRUE,
           new_page = TRUE,
           legend=c("Q2 vs. Q1","Q3 vs. Q1","Q4 vs. Q1"),
           legend_args = fpLegend(pos = list("topright"),
                                  title="Legend",
                                  r = unit(0, "snpc"),
                                  gp = gpar(col="#CCCCCC", lwd=1.5)))

1 个答案:

答案 0 :(得分:2)

你可以做的一件事是使用&#34;常规&#34;在森林地图的呼叫之外呼叫legend 要做到这一点,您首先必须致电plot.new

plot.new()
forestplot(...) # without the legend part
legend("topright", c("Q2 vs. Q1","Q3 vs. Q1","Q4 vs. Q1"), title="Legend", border="#CCCCCC", box.lwd=1.5, 
       col=c("blue", "red", "green"), pch=c(16, 15, 18))