0

我正在尝试创建一个看起来像这样的森林图 -->

图。1

在此处输入图像描述

我在创建图例时遇到了困难,如图右侧所示。

我的数据如下:

Gene_ID HR      low     high
Gene_1  0.83    0.78    0.89
Gene_2  0.61    0.51    0.74
Gene_3  0.85    0.8     0.9
Gene_4  0.77    0.7     0.84
Gene_5  0.75    0.68    0.83
Gene_6  0.81    0.76    0.87
Gene_7  0.85    0.81    0.9
Gene_8  0.8     0.74    0.86
Gene_9  0.82    0.76    0.88
Gene_10 0.8     0.73    0.87

我能够得到情节,但我无法得到如图 1 右侧所示的图例。

我的代码如下:

library(forestplot)
genes_df <- read.table("data.txt", header=T, sep="\t")

data <- structure(list(HR  = c(NA,genes_df$HR), 
                       low = c(NA,genes_df$low),
                       high = c(NA,genes_df$high)),
                       .Names = c("HR", "low", "high"), 
                       row.names = c(NA,-11L), 
                       class = "data.frame")

labels <- cbind(c("Gene_ID","Gene_1","Gene_2","Gene_3","Gene_4","Gene_5","Gene_6","Gene_7","Gene_8","Gene_9","Gene_10"),
                   c("HR","0.83","0.61","0.85","0.77","0.75","0.81","0.85","0.8","0.82","0.8"),
                   c("low","0.78","0.51","0.8","0.7","0.68","0.76","0.81","0.74","0.76","0.73"),
                   c("high","0.89","0.74","0.9","0.84","0.83","0.87","0.9","0.86","0.88","0.87"))

print("....Creating the plot....")                 
jpeg(filename="Hazard_ratio_plot.jpg",units="cm",width=20,height=17, res=800)
forestplot(labels, 
           data,new_page = TRUE,
           boxsize = .25,
           zero = 0.707,
           ci.vertices = TRUE,
           ci.vertices.height = 0.25,
           xlog=TRUE, 
           cex = 0.1,
           graph.pos = 2,
           lwd.zero = gpar(lty=1, alpha = 1),
           lineheight = "auto",
           title = "Hazard ratio plot",
           txt_gp = fpTxtGp(label=gpar(fontfamily="Calibri")),
           col = fpColors(box="blue",line="black",zero = "black"),
           xlab="Hazard ratio")
dev.off()

我的 y 轴标签具有列中的所有值,Gene_ID、HR、低和高。使用参数graph.pos = 2,我可以分离 y 轴标签:HR、low 和 high 并将其放在图的右侧,使其看起来像图例。

但是,当我尝试相同的方法来获取带有参数“legend”的图例时,我收到以下错误:

fn.legend[[i]] 中的错误:“闭包”类型的对象不可子集

我不明白这个错误是什么。

4

1 回答 1

1

决定图表列的参数是:graph.pos

forestplot(main_list,
           coef,
           low,
           high,
           graph.pos = 1,
           xlog = TRUE,
           zero = 0.75,
           boxsize=0.25,
           col = fpColors(box="black",line="darkblue"),
           ci.vertices = TRUE,
           ci.vertices.height = 0.25,
           #legend = "HR",
           #legend_args = fpLegend(pos = list("topright"),title="95%- CI",r = unit(.1, "snpc"),gp = gpar(col="#CCCCCC", lwd=1.5)),
           lineheight = "auto",
           xlab = "Hazard ratio",
           title = "Hazard ratio plot")
于 2018-03-18T20:40:20.513 回答