R语言绘制高级森林图(1)

使用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

 

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值