dxy logo
首页丁香园病例库全部版块
搜索
登录

孟德尔随机化森林图代码

发布于 2023-11-24 · 浏览 3396 · IP 甘肃甘肃
这个帖子发布于 1 年零 168 天前,其中的信息可能已发生改变或有所发展。

getwd()

install.packages("forestploter")

library(grid)

library(forestploter)

library(openxlsx)

dt <- read.xlsx("fores总.xlsx")

dt$` ` <- paste(rep(" ", 20), collapse = " ")

dt$'OR(95%CI)'<-ifelse(is.na(dt$OR),"",

            sprintf('%.2f(%.2f to %.2f)',

                dt$OR,dt$OR_lci95,dt$OR_uci95))

dt[is.na(dt)] <- " "

tm <- forest_theme(base_size = 10, # 基础大小

          # 可信区间点的形状,线型、颜色、宽度

          ci_pch = 20,

          ci_col = "#4575b4", # #762a83

          ci_lty = 1,

          ci_lwd = 2.3,

          ci_Theight = 0.2, # 可信区间两端加短竖线

          

          # 参考线宽度、形状、颜色

          refline_lwd = 1.5,

          refline_lty = "dashed",

          refline_col = "red",

          

          # 汇总菱形的填充色和边框色

          summary_fill = "#4575b4",

          summary_col = "#4575b4",

          

          # 脚注大小、字体、颜色

          footnote_cex = 1.1,

          footnote_fontface = "italic",

          footnote_col = "blue")

p <- forest(dt[,c(1,7.6,3)],#选择数据4-7列和9列作为森林图元素

      est = dt$OR,#HR

      lower = dt$OR_lci95,#可信区间下限

      upper = dt$OR_uci95,#可信区间上限

      sizes = 0.6,#点估计框大小,用标准误映射

      ci_column = 3,#可信区间在第几列展示

      ref_line = 1,

      xlim = c(0,2),

      ticks_at = c(0,1,2),

      arrow_lab = c('protective factor','risk factor'),

      theme = tm)#主题

print(p)

png(filename = 'MR结果.tif',width = 4500,height = 2800,res = 350) #tif格式 设置分辨率

print(p)

dev.off()

最后编辑于 2023-11-24 · 浏览 3396

1 10 1

全部讨论0

默认最新
avatar
1
分享帖子
share-weibo分享到微博
share-weibo分享到微信
认证
返回顶部