森林圖 (forestplot包)
在Meta分析中森林圖比較常見(jiàn),但其實(shí)掌握了用R語(yǔ)言中的forestplot包繪制森林圖的各個(gè)用法,森林圖可以用于表示其他數(shù)據(jù)類型各組間的指標(biāo)的中值和四分位距的范圍。它是在平面直角坐標(biāo)系中,以一條垂直的無(wú)效線(橫坐標(biāo)刻度為1或0)為中心,平行于橫軸的多條線段描述了每個(gè)組的指標(biāo)的中值和可信區(qū)間,最后一行(Summary)則用棱形(或其它圖形)描述了多個(gè)組別合并的效應(yīng)量及可信區(qū)間。
首先安裝forestplot 包:
install.packages("forestplot")
主函數(shù) forestplot :
用法:
forestplot(labeltext, mean, lower, upper, align, is.summary = FALSE, graph.pos = "right", hrzl_lines, clip = c(-Inf, Inf), xlab = "", zero = ifelse(xlog, 1, 0), graphwidth = "auto", colgap, lineheight = "auto", line.margin, col = fpColors(), txt_gp = fpTxtGp(), xlog = FALSE, xticks, xticks.digits = 2, grid = FALSE, lwd.xaxis, lwd.zero, lwd.ci, lty.ci = 1, ci.vertices, ci.vertices.height = 0.1, boxsize, mar = unit(rep(5, times = 4), "mm"), title, legend, legend_args = fpLegend(), new_page = getOption("forestplot_new_page", TRUE), fn.ci_norm = fpDrawNormalCI, fn.ci_sum = fpDrawSummaryCI, fn.legend, ...)
參數(shù):這里只列出了大部分參數(shù),還有一些比較不常用的可以自行探索
labeltext主要是以矩陣或者list形式將數(shù)據(jù)導(dǎo)入函數(shù),最好以矩陣,因?yàn)閿?shù)據(jù)一般都是矩陣的。mean誤差條的均值lower誤差條 95%置信區(qū)間下限upper誤差條 95%置信區(qū)間上限align每列文字的對(duì)齊方式,偶爾會(huì)用到。如:align=c("l","c","c")l:左對(duì)齊r:右對(duì)齊c:居中對(duì)齊is.summary主要的功能是讓表格的每一行字體出現(xiàn)差異,從而區(qū)分表頭。其值主要用TRUE/FALSE進(jìn)行差異化分配。graph.pos定位森林圖所在的位置。通過(guò)數(shù)字來(lái)確定為第幾列。hrzl_lines以list形式設(shè)置表中線條的類型、影響范圍。Eg:“3”=gpar(lwd=1,columns=1:4,col=’red’)意思就是第3行的線條,寬度為1,線段延伸至第四列。Col指的顏色。clipx軸的最大最小范圍xlabx軸的標(biāo)題zero森林圖中基準(zhǔn)線的位置(無(wú)效線的橫坐標(biāo))graphwidth森林圖在表中的寬度如:graphwidth = unit(.4,"npc")colgap
列與列之間的間隙寬度,默認(rèn)是 6 mm,需要用 unit 的形式
lineheight行的高度,可以是數(shù)字,也可以是 unit 的形式line.margin行與行之間的間隙的寬度col森林圖橫線以及點(diǎn)的顏色。box:box(點(diǎn)估計(jì)值)的顏色line:穿過(guò)方塊的橫線的顏色zero:中間那條基準(zhǔn)線的顏色summary:summary中菱形的顏色hrz_lines:表中第一條橫線的顏色eg:col=fpcolors(box=’royblue’,line=’darkblue’, summary=’royblue’, hrz_lines=’red’)txt_gp設(shè)置表格中文本的格式:用gpar進(jìn)行賦值,其中cex為文本字體大小,ticks為坐標(biāo)軸大小,xlab為坐標(biāo)軸文字字體大小。label:表格主體文字的格式ticks:森林圖下方的坐標(biāo)軸的刻度文字格式xlab:定義的x軸標(biāo)題格式title:標(biāo)題文字的格式eg:txt_gp=fpTxtGp(label=gpar(cex=1.25), ticks=gpar(cex=1.1), xlab=gpar(cex = 1.2), title=gpar(cex = 1.2))xticks橫坐標(biāo)刻度根據(jù)需要可隨意設(shè)置,如:xticks = c(0.5, 1,1.5, 2)lwd.xaxisX軸線寬lwd.zero無(wú)效線的寬度lwd.ci置信區(qū)間線條的寬度(粗細(xì))lty.ci置信區(qū)間的線條類型ci.vertices森林圖可信區(qū)間兩端添加小豎線(TRUE)ci.vertices.height設(shè)置森林圖可信區(qū)間兩端的小豎線高度,默認(rèn)是10%行高boxsizebox(點(diǎn)估計(jì)值)的大小mar圖形頁(yè)邊距,如:mar=unit(rep(1.25, times = 4), "cm")title添加標(biāo)題legend當(dāng)同時(shí)顯示多個(gè)置信區(qū)間時(shí),需要添加圖例
new_page
是否新頁(yè)fn.ci_normbox(點(diǎn)估計(jì)值)的形狀,默認(rèn)是方塊。如:fn.ci_norm="fpDrawDiamondCI":box 類型選擇鉆石
示例代碼①:先從構(gòu)建的最簡(jiǎn)單的數(shù)據(jù)開(kāi)始
# 構(gòu)建示例數(shù)據(jù)
library(forestplot)# Cochrane data from the 'rmeta'-packagecochrane_from_rmeta <- structure(list( mean =c(NA, NA, 0.578, 0.165, 0.246, 0.700, 0.348, 0.139, 1.017, NA, 0.531), lower =c(NA, NA, 0.372, 0.018, 0.072, 0.333, 0.083, 0.016, 0.365, NA, 0.386), upper =c(NA, NA, 0.898, 1.517, 0.833, 1.474, 1.455, 1.209, 2.831, NA, 0.731)), .Names =c("mean", "lower", "upper"), row.names =c(NA, -11L), class ="data.frame")
tabletext<-cbind(c("", "Study", "Auckland", "Block","Doran", "Gamsu", "Morrison", "Papageorgiou","Tauesch", NA, "Summary"),c("Deaths", "(steroid)", "36", "1","4", "14", "3", "1","8", NA, NA),c("Deaths", "(placebo)", "60", "5","11", "20", "7", "7","10", NA, NA),c("", "OR", "0.58", "0.16","0.25", "0.70", "0.35", "0.14","1.02", NA, "0.53"))
以下使用 forestplot 函數(shù)畫森林圖,注意查看每個(gè)代碼發(fā)生變化的參數(shù)以及對(duì)應(yīng)圖片中明顯變化的地方。
forestplot(tabletext, graph.pos =4, hrzl_lines =list("3"=gpar(lty=2), "11" =gpar(lwd=1, columns=c(1:3,5), col ="#000044"), "12" =gpar(lwd=1, lty=2, columns=c(1:3,5), col ="#000044")), cochrane_from_rmeta,new_page =TRUE, is.summary=c(TRUE,TRUE,rep(FALSE,8),TRUE), clip=c(0.1,2.5), xlog=TRUE, col=fpColors(box="royalblue",line="darkblue",summary="royalblue",hrz_lines ="#444444"))
forestplot(tabletext, graph.pos =4, hrzl_lines =list("3"=gpar(lty=2,col ="red"), "11" =gpar(lwd=1, columns=c(1:3,5), col ="#000044"), "12" =gpar(lwd=1, lty=2, columns=c(1:3,5), col ="#000044")), cochrane_from_rmeta,new_page =TRUE, is.summary=c(TRUE,TRUE,rep(FALSE,8),TRUE), clip=c(0.1,2.5), xlog=TRUE, col=fpColors(box="royalblue",line="darkblue",summary="royalblue",hrz_lines ="#444444"))
forestplot(tabletext, graph.pos =4, hrzl_lines =list("3"=gpar(lty=2), "11" =gpar(lwd=1, columns=c(1:3,5), col ="red"), "12" =gpar(lwd=1, lty=2, columns=c(1:3,5), col ="#000044")), cochrane_from_rmeta,new_page =TRUE, is.summary=c(TRUE,TRUE,rep(FALSE,8),TRUE), clip=c(0.1,2.5), xlog=TRUE, col=fpColors(box="royalblue",line="darkblue",summary="royalblue",hrz_lines ="#444444"))
forestplot(tabletext, graph.pos =4, hrzl_lines =list("3"=gpar(lty=2), "11" =gpar(lwd=1, columns=c(1:3,5), col ="#000044"), "12" =gpar(lwd=1, lty=2, columns=c(1:3,5), col ="red")), cochrane_from_rmeta,new_page =TRUE, is.summary=c(TRUE,TRUE,rep(FALSE,8),TRUE), clip=c(0.1,2.5), xlog=TRUE, col=fpColors(box="royalblue",line="darkblue",summary="royalblue",hrz_lines ="#444444"))
forestplot(tabletext, graph.pos =4, hrzl_lines =list("3"=gpar(lty=2), "11" =gpar(lwd=1, columns=c(1:3,5), col ="#000044"), "12" =gpar(lwd=1, lty=2, columns=c(1:3,5), col ="#000044")), cochrane_from_rmeta,new_page =TRUE, is.summary=c(TRUE,TRUE,rep(FALSE,8),TRUE), clip=c(0.1,2.5), xlog=TRUE, col=fpColors(box="red",line="darkblue",summary="royalblue",hrz_lines ="#444444"))
forestplot(tabletext, graph.pos =4, hrzl_lines =list("3"=gpar(lty=2), "11" =gpar(lwd=1, columns=c(1:3,5), col ="#000044"), "12" =gpar(lwd=1, lty=2, columns=c(1:3,5), col ="#000044")), cochrane_from_rmeta,new_page =TRUE, is.summary=c(TRUE,TRUE,rep(FALSE,8),TRUE), clip=c(0.1,2.5), xlog=TRUE, col=fpColors(box="royalblue",line="red",summary="royalblue",hrz_lines ="#444444"))
forestplot(tabletext, graph.pos =4, hrzl_lines =list("3"=gpar(lty=2), "11" =gpar(lwd=1, columns=c(1:3,5), col ="#000044"), "12" =gpar(lwd=1, lty=2, columns=c(1:3,5), col ="#000044")), cochrane_from_rmeta,new_page =TRUE, is.summary=c(TRUE,TRUE,rep(FALSE,8),TRUE), clip=c(0.1,2.5), xlog=TRUE, col=fpColors(box="royalblue",line="darkblue",summary="red",hrz_lines ="#444444"))
forestplot(tabletext, graph.pos =4, hrzl_lines =list("3"=gpar(lty=2), "11" =gpar(lwd=1, columns=c(1:3,5), col ="#000044"), "12" =gpar(lwd=1, lty=2, columns=c(1:3,5), col ="#000044")), cochrane_from_rmeta,new_page =TRUE, is.summary=c(TRUE,TRUE,rep(FALSE,8),TRUE), clip=c(0.1,2.5), xlog=TRUE, col=fpColors(box="royalblue",line="darkblue",summary="royalblue",hrz_lines ="red"))
# 添加標(biāo)題forestplot(tabletext, graph.pos =4, title="Hazard Ratio", hrzl_lines =list("3"=gpar(lty=2), "11" =gpar(lwd=1, columns=c(1:3,5), col ="#000044"), "12" =gpar(lwd=1, lty=2, columns=c(1:3,5), col ="#000044")), cochrane_from_rmeta,new_page =TRUE, is.summary=c(TRUE,TRUE,rep(FALSE,8),TRUE), clip=c(0.1,2.5), xlog=TRUE, col=fpColors(box="royalblue",line="darkblue",summary="royalblue",hrz_lines ="#444444"))
# 定義x軸forestplot(tabletext, graph.pos =4, title="Hazard Ratio", hrzl_lines =list("3"=gpar(lty=2), "11" =gpar(lwd=1, columns=c(1:3,5), col ="#000044"), "12" =gpar(lwd=1, lty=2, columns=c(1:3,5), col ="#000044")), cochrane_from_rmeta,new_page =TRUE, is.summary=c(TRUE,TRUE,rep(FALSE,8),TRUE), xlab=" <---PCI Better--- ---Medical Therapy Better--->", clip=c(0.1,2.5), xlog=TRUE, col=fpColors(box="royalblue",line="darkblue",summary="royalblue",hrz_lines ="#444444"))
# 取消對(duì)頭2行和最后1行字體的特殊設(shè)置forestplot(tabletext, graph.pos =4, title="Hazard Ratio", hrzl_lines =list("3"=gpar(lty=2), "11" =gpar(lwd=1, columns=c(1:3,5), col ="#000044"), "12" =gpar(lwd=1, lty=2, columns=c(1:3,5), col ="#000044")), cochrane_from_rmeta,new_page =TRUE, is.summary=c(rep(FALSE,11)), xlab=" <---PCI Better--- ---Medical Therapy Better--->", clip=c(0.1,2.5), xlog=TRUE, zero=1, col=fpColors(box="royalblue",line="darkblue",summary="royalblue",hrz_lines ="#444444"))
示例代碼②:需要定義亞組的數(shù)據(jù)
### 準(zhǔn)備數(shù)據(jù)
library(forestplot)#數(shù)據(jù)來(lái)源:https://www.r-bloggers.com/forest-plot-with-h(huán)orizontal-bands/data <- read.csv("forestplotdata.csv", stringsAsFactors=FALSE)
head(data)# Variable Count Percent Point.Estimate Low High PCI.Group Medical.Therapy.Group P.Value# 1 Overall 2166 100 1.3 0.90 1.50 17.2 15.6 NA# 2 NA NA NA NA NA NA NA NA# 3 Age NA NA NA NA NA NA NA 0.05# 4 <= 65 1534 71 1.5 1.05 1.90 17.0 13.2 NA# 5 > 65 632 29 0.8 0.60 1.25 17.8 21.3 NA# 6 NA NA NA NA NA NA NA NA
### 繪制森林圖
## 簡(jiǎn)單森林圖
# 構(gòu)建tabletext,更改列名稱,將 count 和 percent 合并np <- ifelse(!is.na(data$Count), paste(data$Count," (",data$Percent,")",sep=""), NA)View(np)
# 寫出將要在圖中展現(xiàn)出來(lái)的文本tabletext <- cbind(c("Subgroup","",data$Variable), c("No. of Patients (%)","",np), c("4-Yr Cum. Event Rate PCI","",data$PCI.Group), c("4-Yr Cum. Event Rate Medical Therapy","",data$Medical.Therapy.Group), c("P Value","",data$P.Value)View(tabletext)
##繪制森林圖forestplot(labeltext=tabletext, graph.pos=3, mean=c(NA,NA,data$Point.Estimate), lower=c(NA,NA,data$Low), upper=c(NA,NA,data$High), boxsize=0.5)
接下來(lái)要對(duì)森林圖進(jìn)行優(yōu)化:
## 定義亞組subgps <- c(4,5,8,9,12,13,16,17,20,21,24,25,28,29,32,33)data$Variable[subgps] <- paste(" ",data$Variable[subgps])View(data)
png(filename = "Forestplot.png",width=960, height=640)forestplot(labeltext=tabletext, graph.pos=3, #為Pvalue箱線圖所在的位置 mean=c(NA,NA,data$Point.Estimate), lower=c(NA,NA,data$Low), upper=c(NA,NA,data$High), title="Hazard Ratio Plot", #定義標(biāo)題 xlab=" <---PCI Better--- ---Medical Therapy Better--->", #定義x軸 ##根據(jù)亞組的位置,設(shè)置線型,寬度造成“區(qū)塊感” hrzl_lines=list("3" = gpar(lwd=1, col="black"), "7" = gpar(lwd=60, lineend="butt", columns=c(2:6), col="#99999922"), "15" = gpar(lwd=60, lineend="butt", columns=c(2:6), col="#99999922"), "23" = gpar(lwd=60, lineend="butt", columns=c(2:6), col="#99999922"), "31" = gpar(lwd=60, lineend="butt", columns=c(2:6), col="#99999922")), #fpTxtGp函數(shù)中的cex參數(shù)設(shè)置各部分字體大小 txt_gp=fpTxtGp(label=gpar(cex=1.25), ticks=gpar(cex=1.1), xlab=gpar(cex = 1.2), title=gpar(cex = 1.2)), col=fpColors(box="#1c61b6", lines="#1c61b6", zero = "gray50"), ##fpColors函數(shù)設(shè)置顏色 zero=1, #箱線圖中基準(zhǔn)線的位置 cex=0.9, lineheight = "auto", colgap=unit(8,"mm"), lwd.ci=2, boxsize=0.5, #箱子大小,線的寬度 ci.vertices=TRUE, ci.vertices.height = 0.4) #森林圖可信區(qū)間兩端添加小豎線,設(shè)置高度dev.off()
森林圖怎么看:
(1)森林圖中橫短線與中線相交表示無(wú)統(tǒng)計(jì)學(xué)意義;
(2)95% CI上下限均>1,即在森林圖中,其95% CI橫線不與無(wú)效豎線相交,且該橫線落在無(wú)效線右側(cè)時(shí),說(shuō)明該指標(biāo)大于豎線代表的結(jié)局;
(3)95% CI上下限均<1,即在森林圖中,其95% CI橫線不與無(wú)效豎線相交,且該橫線落在無(wú)效線左側(cè)時(shí),說(shuō)明該指標(biāo)小于于豎線代表的結(jié)局。
(4)最后以菱形所在位置代表總體的評(píng)價(jià)結(jié)果。具體數(shù)據(jù)具體分析哈!
發(fā)表評(píng)論
請(qǐng)輸入評(píng)論內(nèi)容...
請(qǐng)輸入評(píng)論/評(píng)論長(zhǎng)度6~500個(gè)字
圖片新聞
-
金百澤科技亮相中國(guó)國(guó)際醫(yī)療器械博覽會(huì) | 盡顯醫(yī)療領(lǐng)域硬實(shí)力
-
進(jìn)階的新冠疫苗 又一個(gè)中國(guó)造
-
“AI醫(yī)療第一股”鷹瞳科技上市首日即破發(fā)
-
圓心科技登陸港股,“賣藥的生意”還好不好做?
-
十圖解讀2021年中國(guó)康復(fù)醫(yī)療行業(yè)現(xiàn)狀
-
醫(yī)藥流通數(shù)字化運(yùn)營(yíng)實(shí)現(xiàn)精細(xì)化飼養(yǎng)
-
科學(xué)家發(fā)現(xiàn)人體新器官:將有助于癌癥治療
-
李飛飛入選美國(guó)國(guó)家醫(yī)學(xué)院
最新活動(dòng)更多
-
11月19日立即報(bào)名>> 【線下論壇】華邦電子與恩智浦聯(lián)合技術(shù)論壇
-
11月29日立即預(yù)約>> 【上海線下】設(shè)計(jì),易如反掌—Creo 11發(fā)布巡展
-
即日-12.26火熱報(bào)名中>> OFweek2024中國(guó)智造CIO在線峰會(huì)
-
精彩回顧立即查看>> 2024(第五屆)全球數(shù)字經(jīng)濟(jì)產(chǎn)業(yè)大會(huì)暨展覽會(huì)
-
精彩回顧立即查看>> 全數(shù)會(huì)2024中國(guó)人形機(jī)器人技術(shù)創(chuàng)新發(fā)展大會(huì)
-
精彩回顧立即查看>> OFweek 2024中國(guó)激光產(chǎn)業(yè)高質(zhì)量發(fā)展峰會(huì)
-
9 BD新浪潮
- 1 南京殺出超級(jí)IPO:年入27億,華東第一
- 2 從巨額回購(gòu) 看石藥集團(tuán)的“三張”價(jià)值底牌
- 3 被華為刷屏的腦機(jī)接口芯片,有多前沿?
- 4 中國(guó)藥企出海的“PlanB”
- 5 星形膠質(zhì)細(xì)胞為阿爾茨海默病治療帶來(lái)可能
- 6 聯(lián)影醫(yī)療:貢獻(xiàn)超億元收入上演控制權(quán)迷局
- 7 慢下來(lái)的邁瑞醫(yī)療
- 8 石藥集團(tuán)的陽(yáng)謀
- 9 聯(lián)影醫(yī)療:原子公司變關(guān)聯(lián)方后或“藕斷絲連”
- 10 血管化器官芯片應(yīng)用前景廣闊
- 高級(jí)軟件工程師 廣東省/深圳市
- 自動(dòng)化高級(jí)工程師 廣東省/深圳市
- 光器件研發(fā)工程師 福建省/福州市
- 銷售總監(jiān)(光器件) 北京市/海淀區(qū)
- 激光器高級(jí)銷售經(jīng)理 上海市/虹口區(qū)
- 光器件物理工程師 北京市/海淀區(qū)
- 激光研發(fā)工程師 北京市/昌平區(qū)
- 技術(shù)專家 廣東省/江門市
- 封裝工程師 北京市/海淀區(qū)
- 結(jié)構(gòu)工程師 廣東省/深圳市