跟著 Nature Communication 學(xué)作圖 | 百分比堆積柱狀圖+卡方檢驗(yàn)

跟著 Nature Communication 學(xué)作圖 | 百分比堆積柱狀圖+卡方檢驗(yàn)

stack_barplot.jpg

今天我們復(fù)現(xiàn)一幅2021年6月發(fā)表在nature communications上的熱圖。

Title:Molecular determinants of response to PD-L1 blockade across tumor types

DOI:https://doi.org/10.1038/s41467-021-24112-w

之前復(fù)現(xiàn)過的堆積柱狀圖

  1. 跟著Nat Commun學(xué)作圖 | 3.物種豐度堆積柱狀圖
  2. R繪圖 | 圓角堆疊柱狀圖(ggchicklet )

22

本期圖片

NC_stack_barplot.png

結(jié)果展示

[圖片上傳失敗...(image-1d02f0-1661733048420)]

以上是在R中復(fù)現(xiàn)的圖片,剩下的細(xì)節(jié)可以在AI中修改,本文不再贅述。

示例數(shù)據(jù)和代碼領(lǐng)取

[圖片上傳失敗...(image-a18ab5-1661733048420)]

繪制

# 建立數(shù)據(jù)
mydata <- data.frame(id = 1:98,
                     ORR = c(rep("SD", 54), rep("CR", 44)),
                     PD_1 = c(rep("TC0", 8), rep("TC1", 19), rep("TC2", 27),
                                  rep("TC0", 6), rep("TC1", 13), rep("TC2", 25)))

head(mydata) # 查看前6行

# 卡方檢驗(yàn)
## 將數(shù)據(jù)整理為四格表
ka<-xtabs(~mydata$PD_1+mydata$ORR,data=mydata)
ka
# 卡方檢驗(yàn)
chisq.test(ka)
# 百分比柱狀圖
library(scales)
library(ggplot2)
library(RColorBrewer)
p <- ggplot(mydata, aes(x = ORR, fill = PD_1)) +
  geom_bar(width = 0.9, position = "fill") + # 百分比柱狀圖
  scale_fill_brewer(palette = "Greens")  +
  scale_y_continuous(labels = percent) +
  labs(title = "mUC",
       y = "Patients Percentage")+
  theme(panel.grid.major=element_blank(),
        panel.grid.minor=element_blank(),
        panel.background = element_blank(),
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank(),
        axis.title.x = element_blank(),
        plot.title = element_text(hjust = 0.5, face="bold"))
p

p1 <- p + coord_cartesian(clip = 'off', ylim = c(0,1))+ 
  theme(plot.margin = margin(0.5,0.5,1.2,0.5,'cm'))+ #自定義圖片上左下右的邊框?qū)挾?  annotate( "text",
           cex=5,
           x=1.5, y=-0.15, # 根據(jù)自己的數(shù)據(jù)調(diào)節(jié)p value的位置
           label='p = 0.760', # 添加P值
           color="black")+
  annotate("rect", xmin = 0.55, xmax = 1.45, ymin = -0.1, ymax = -0.02, 
           fill = "#40a1cf")+
  annotate("rect", xmin = 1.55, xmax = 2.45, ymin = -0.1, ymax = -0.02, 
           fill = "#dd816d")
p1
## 同理話另外兩個(gè) 且不顯示y軸
p2 <- p1+theme(
  axis.text.y = element_blank(),
  axis.ticks.y = element_blank(),
  axis.title.y = element_blank()
)
p2

## 拼圖
#install.packages("patchwork")
library(patchwork)
p1+ p2+ p2 + plot_layout(guides = 'collect')
ggsave('stack_barplot.pdf',width = 8,height = 6)

[圖片上傳失敗...(image-916ad8-1661733048420)]

往期內(nèi)容

  1. 即將滿員!CNS圖表復(fù)現(xiàn)|生信分析|R繪圖 資源分享&討論群!(內(nèi)附推文合集)
  2. 跟著 Nature Communication 學(xué)作圖 | 熱圖+格子注釋(通路富集相關(guān))
  3. R繪圖 | 時(shí)間線熱圖

[圖片上傳失敗...(image-85f5e5-1661733048420)]

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容