1.需求
为了直观的展示免疫治疗结果与病人风险高低之间的关系,如图:
2.数据
需要病人的高低风险分组,和免疫治疗结果
set.seed(10086)
meta = data.frame(Sample = paste0("sample",1:100),
Response = sample(c("SD/PD","CR/PR"),100,replace = T),
risk = sample(c("High","Low"),100,replace = T))
head(meta)
## Sample Response risk
## 1 sample1 CR/PR Low
## 2 sample2 CR/PR High
## 3 sample3 SD/PD Low
## 4 sample4 SD/PD Low
## 5 sample5 SD/PD Low
## 6 sample6 CR/PR High
3.画图代码
library(dplyr)
dat = count(meta,risk,Response)
dat = dat %>% group_by(risk) %>%
summarise(Response = Response,n = n/sum(n))
dat$Response = factor(dat$Response,levels = c("SD/PD","CR/PR"))
dat
## # A tibble: 4 x 3
## # Groups: risk [2]
## risk Response n
## <chr> <fct> <dbl>
## 1 High CR/PR 0.628
## 2 High SD/PD 0.372
## 3 Low CR/PR 0.474
## 4 Low SD/PD 0.526
library(ggplot2)
ggplot(data = dat)+
geom_bar(aes(x = risk,y = n,
fill = Response),
stat = "identity")+
scale_fill_manual(values = c("#f87669","#2fa1dd"))+
geom_text(aes(x = risk,y = n,
label = scales::percent(n)),
color = "white",
size = 6,
position = position_fill(vjust = 0.5))+
theme_minimal()+
theme(legend.position = "top")
因为数据是编的,就不用看high和low两组免疫治疗结果好坏所占的比例啦。实战数据再看即可。