R語(yǔ)言繪圖包系列:
- R語(yǔ)言繪圖包01--優(yōu)秀的拼圖包patchwork
- R語(yǔ)言繪圖包02--熱圖pheatmap
- R語(yǔ)言繪圖包03--火山圖EnhancedVolcano
- R語(yǔ)言繪圖包04--GOplot:富集分析結(jié)果可視化
- R語(yǔ)言繪圖包05--韋恩圖的繪制:ggvenn和VennDiagram
- R語(yǔ)言繪圖包06--基因表達(dá)相關(guān)性繪圖corrplot
- R語(yǔ)言繪圖包07--多集合可視化UpSetR
1. 基本用法和參數(shù)
forestplot(...)
# S3 method for data.frame
forestplot(x, mean, lower, upper, labeltext, is.summary, ...)
# S3 method for default
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,
shapes_gp = fpShapesGp(),
...
)
# S3 method for gforge_forestplot
print(x, ...)
# S3 method for gforge_forestplot
plot(x, y, ...)
# S3 method for grouped_df
forestplot(x, labeltext, mean, lower, upper, legend, is.summary, ...)
參數(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è)置表中線條的類(lèi)型只搁、影響范圍。Eg:“3”=gpar(lwd=1,columns=1:4,col=’red’)意思就是第3行的線條唯鸭,寬度為1须蜗,線段延伸至第四列。Col指的顏色目溉。 |
clip | x軸的最大最小范圍 |
xlab | x軸的標(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.xaxis | X軸線寬 |
lwd.zero | 無(wú)效線的寬度 |
lwd.ci | 置信區(qū)間線條的寬度(粗細(xì)) |
lty.ci | 置信區(qū)間的線條類(lèi)型 |
ci.vertices | 森林圖可信區(qū)間兩端添加小豎線(TRUE) |
ci.vertices.height | 設(shè)置森林圖可信區(qū)間兩端的小豎線高度,默認(rèn)是10%行高 |
boxsize | box(點(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_norm | box(點(diǎn)估計(jì)值)的形狀,默認(rèn)是方塊。如:fn.ci_norm="fpDrawDiamondCI":box 類(lèi)型選擇鉆石 |
參考:forestplot: Draws a forest plot
2. 森林圖的繪制
library(forestplot)
rs_forest <- read.csv('demo.csv',header = FALSE)
rs_forest
# V1 V2 V3 V4 V5 V6 V7
# 1 Group Case/Control p OR(95%CI) NA NA NA
# 2 Age NA NA NA
# 3 <50 127/211 2.43E-11 4.24(2.84~6.66) 4.24 2.84 6.66
# 4 50-59 115/244 4.14E-12 5.48(3.5~9.2) 5.48 3.50 9.20
# 5 >=60 132/237 1.25E-08 2.74(1.96~3.93) 2.74 1.96 3.93
# 6 Sex NA NA NA
# 7 Male 323/318 1.00E-15 3.46(2.71~4.5) 3.46 2.71 4.50
# 8 Female 51/374 3.14E-09 4.21(2.69~7.01) 4.21 2.69 7.01
# 9 Smoking NA NA NA
# 10 Yes 122/171 2.06E-07 2.56(1.82~3.71) 2.56 1.82 3.71
# 11 No 252/521 1.00E-15 4.16(3.17~5.59) 4.16 3.17 5.59
# 12 Hypertension NA NA NA
# 13 Yes 193/207 3.31E-12 3.14(2.31~4.4) 3.14 2.31 4.40
# 14 No 181/485 1.00E-15 3.96(2.95~5.45) 3.96 2.95 5.45
# 15 Drinking NA NA NA
# 16 Yes 83/111 2.44E-04 2.42(1.55~4.01) 2.42 1.55 4.01
# 17 No 291/581 1.00E-15 3.83(3.01~4.96) 3.83 3.01 4.96
forestplot(labeltext = as.matrix(rs_forest[,c(1:4)]),
mean = rs_forest$V5,
lower = rs_forest$V6,
upper = rs_forest$V7,
is.summary=c(T,T,F,F,F,T,F,F,T,F,F,T,F,F,T,F,F),
zero = 1,
boxsize = 0.5,
lineheight = unit(6,'mm'),
graphwidth = unit(35,'mm'),
colgap = unit(2,'mm'),
lwd.zero = 2,
lwd.ci = 2,
col=fpColors(box='#ef233c',summary="#9e2a2b",lines = 'blue1',zero = 'grey'),
xlab="Odds Ratio",
lwd.xaxis=2,
lty.ci = "solid", ci.vertices.height = 0.15,clip=c(1,13),xticks.digits = 6,
graph.pos = 4)
forestplot(labeltext = as.matrix(rs_forest[,c(1:4)]),
mean = rs_forest$V5,
lower = rs_forest$V6,
upper = rs_forest$V7,
is.summary=c(T,T,F,F,F,T,F,F,T,F,F,T,F,F,T,F,F),
graph.pos=4, #為Pvalue箱線圖所在的位置
#定義標(biāo)題
title="Hazard Ratio Plot",
##定義x軸
xlab=" <---PCI Better--- ---Medical Therapy Better--->",
##根據(jù)亞組的位置镊讼,設(shè)置線型宽涌,寬度造成“區(qū)塊感”
#hrzl_lines=list("2" = gpar(lwd=1, lineend="butt", columns=c(1:5),col="#99999922"),
# "18" = gpar(lwd=1, lineend="butt", columns=c(1:5),col="#99999922")),
#fpTxtGp函數(shù)中的cex參數(shù)設(shè)置各個(gè)組件的大小
txt_gp=fpTxtGp(label=gpar(cex=1.25),
ticks=gpar(cex=1.1),
xlab=gpar(cex = 1.2),
title=gpar(cex = 1.2)),
##fpColors函數(shù)設(shè)置顏色
col=fpColors(box="#1c61b6", lines="#1c61b6", zero = "gray50"),
#箱線圖中基準(zhǔn)線的位置
zero=1,
cex=0.9, lineheight = "auto",
colgap=unit(8,"mm"),
#箱子大小,線的寬度
lwd.ci=2, boxsize=0.5,
#箱線圖兩端添加小豎線蝶棋,高度
ci.vertices=TRUE, ci.vertices.height = 0.4)
3. 森林圖結(jié)果解讀
(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é)局京闰。