使用R包plotforestr,以绘制孟德尔随机化中的森林图为例。
#导入符合要求的数据
new_colnames <- paste0(colnames(`IVW(fixed-effect)`), "_2")
colnames(`IVW(fixed-effect)`) <- new_colnames
dt<-cbind(IVW,`IVW(fixed-effect)`)
dt$` `<-paste(rep(" ", dim(dt)[1]), collapse = " ")
dt$` `<-paste(rep(" ", dim(dt)[1]), collapse = " ")
colnames(dt)
设置基本主题
tm <- forest_theme(base_size = 8, # 文字大小
#可信区间
ci_pch = 10,#点形状
ci_col = "red", #颜色
ci_lty = 1,#线条类型
ci_lwd = 4,#线宽度
ci_Theight = 0.2, #两端加短竖线
# 参考线
refline_lwd = 1,#宽度
refline_lty = "dashed",#类型
refline_col = "black",#颜色
# 汇总菱形
summary_fill = "blue",#填充色
summary_col = "blue",#边框色
# 脚注
footnote_cex = 0.6,#大小
footnote_fontface = "italic",#字体
footnote_col = "black")#颜色
绘制图形
p <-forest(dt[,c(3,4,31,15,18,19,32,30)],
est = list(dt$or,
dt$or_2),
lower = list(dt$or_lci95,
dt$or_lci95_2),
upper = list(dt$or_uci95,
dt$or_uci95_2),
ci_column = c(3, 7),
ref_line = 1,
xlim = c(0.01,100),x_trans ="log10",
ticks_at = c(0.01,0.1,1,10,100),
#vert_line = c(1,2),
#nudge_y = 0.2,
theme = tm)
p
#顶部插入信息
p1<-insert_text(p,text =c("IVW","IVW(fixed-effect)"),
col = c(2,6),
part = "header",
gp = gpar(fontface =
"bold"))
p1
#在标题下方加一条下划线
p2 <-add_border(p1,
row =c(1),
col=c(1:3,5:7),
part = "header")
p2
#为标题的两行添加下划线
p3 <-add_border(p2,
row =c(0,2),
col=1:8,
part = "header")
p3