当前位置:   article > 正文

R语言绘制高级森林图(1)_孟德尔随机化森林图代码

孟德尔随机化森林图代码

使用R包plotforestr,以绘制孟德尔随机化中的森林图为例。

  1. #导入符合要求的数据
  2. new_colnames <- paste0(colnames(`IVW(fixed-effect)`), "_2")
  3. colnames(`IVW(fixed-effect)`) <- new_colnames
  4. dt<-cbind(IVW,`IVW(fixed-effect)`)
  5. dt$` `<-paste(rep(" ", dim(dt)[1]), collapse = " ")
  6. dt$` `<-paste(rep(" ", dim(dt)[1]), collapse = " ")
  7. colnames(dt)

设置基本主题

  1. tm <- forest_theme(base_size = 8, # 文字大小
  2. #可信区间
  3. ci_pch = 10,#点形状
  4. ci_col = "red", #颜色
  5. ci_lty = 1,#线条类型
  6. ci_lwd = 4,#线宽度
  7. ci_Theight = 0.2, #两端加短竖线
  8. # 参考线
  9. refline_lwd = 1,#宽度
  10. refline_lty = "dashed",#类型
  11. refline_col = "black",#颜色
  12. # 汇总菱形
  13. summary_fill = "blue",#填充色
  14. summary_col = "blue",#边框色
  15. # 脚注
  16. footnote_cex = 0.6,#大小
  17. footnote_fontface = "italic",#字体
  18. footnote_col = "black")#颜色

绘制图形

  1. p <-forest(dt[,c(3,4,31,15,18,19,32,30)],
  2. est = list(dt$or,
  3. dt$or_2),
  4. lower = list(dt$or_lci95,
  5. dt$or_lci95_2),
  6. upper = list(dt$or_uci95,
  7. dt$or_uci95_2),
  8. ci_column = c(3, 7),
  9. ref_line = 1,
  10. xlim = c(0.01,100),x_trans ="log10",
  11. ticks_at = c(0.01,0.1,1,10,100),
  12. #vert_line = c(1,2),
  13. #nudge_y = 0.2,
  14. theme = tm)
  15. p
  16. #顶部插入信息
  17. p1<-insert_text(p,text =c("IVW","IVW(fixed-effect)"),
  18. col = c(2,6),
  19. part = "header",
  20. gp = gpar(fontface =
  21. "bold"))
  22. p1
  23. #在标题下方加一条下划线
  24. p2 <-add_border(p1,
  25. row =c(1),
  26. col=c(1:3,5:7),
  27. part = "header")
  28. p2
  29. #为标题的两行添加下划线
  30. p3 <-add_border(p2,
  31. row =c(0,2),
  32. col=1:8,
  33. part = "header")
  34. p3

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/574177
推荐阅读
相关标签
  

闽ICP备14008679号