0

我在使用 R 中的森林情节包时遇到了困难。这是我的代码。实际上,除了传说之外,一切都很好。 这是我用我的代码生成的森林图. 然而对于传说,我想要一个蓝色圆圈,一个红色方块和一个绿色的 losange 而不是 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)))
4

1 回答 1

2

您可以做的一件事是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))
于 2015-12-14T13:18:48.623 回答