03.07 Waterfall plot 瀑布圖 R語言

使用場景:

瀑布圖通常用於腫瘤學相關研究,以圖形方式表示每個受試者/樣本對治療的定量反應。在典型的瀑布圖中,x軸用作響應變量的基線值。對於每個受試者/樣本,從基線沿正向或負向繪製豎線,以描繪受試者/樣本響應中自基線的變化。因此,y軸代表響應中相對於基線的變化,通常表示為百分比,例如腫瘤大小的變化百分比或某些標誌物水平的變化百分比。最重要的是,在瀑布圖中,條形圖按百分比變化值的降序排列。

上代碼:

<code>#安裝R包
install.packages("waterfalls")
library(waterfalls)library(ggplot2)
#數讀取數據data #查驗和數據篩選,2-31行,第1,2,11列
data1/<code>

結果1:

id death Per
54 1 17.307692
15 0 16.000000
31 1 15.254237
30 0 15.151515
22 0 14.545455
46 1 13.043478
28 0 11.764706
36 1 10.909091
32 1 7.407407
52 1 7.142857


13 0 7.017544
39 1 6.896552
40 1 4.615385
41 1 3.225806
6 0 2.941176
38 1 1.886792
5 0 0.000000
50 1 0.000000
51 1 -1.666667
45 1 -3.703704
56 1 -3.921569
21 0 -4.225352
34 1 -4.411765
23 0 -4.687500
44 1 -5.172414

47 1 -6.666667

36 1 -10.526316

48 1 -12.307692

1 0 -19.230769

11 0 -29.88505

繪製瀑布圖:

<code>barplot(data$Per,col="blue", border="blue", space=0.5, ylim=c(-30,30),
#圖標題
main = "Waterfall plot for changes in QoL scores",
ylab="Change from baseline (%) in QoL score",
cex.axis=1.2, cex.lab=1.4)/<code>

結果2:

Waterfall plot 瀑布圖  R語言

美化及區別亞組(這裡是生/死,大家可以自己確定亞組):

<code>col barplot(data$Per~data$id, col=col, border=col, space=0.5, ylim=c(-30,30),         
main = "Waterfall plot for changes in QoL scores",
ylab="Change from baseline (%) in QoL score",xlab="ID",         
cex.axis=1.2, cex.lab=1.4, legend.text=c(0,1),
#圖例顯示及設定
args.legend=list(title="Treatment", fill=c("blue","red"), border=NA, cex=0.9,bty = "n"))/<code>


結果3:

Waterfall plot 瀑布圖  R語言

往期回顧:

酷炫樹狀圖(R語言)

基於逆概率加權的生存曲線校正 (R語言)

小提琴圖(R語言)

列線圖 nomogram(R語言)

森林圖(R語言)

生存曲線 (R語言)

SCI寫作神器: AI幫你寫論文

SCI寫作神器: 改寫助手


分享到:


相關文章: