Váraljai, Renáta et al. “Author Correction: Interleukin 17 signaling supports clinical benefit of dual CTLA-4 and PD-1 checkpoint inhibition in melanoma.” Nature cancer vol. 4,9 (2023): 1395. doi:10.1038/s43018-023-00632-w
以下是作者图2中的主要图。
我们本次复现的内容主要有
图2a中的肿瘤生长曲线图:肿瘤生长曲线是动物实验中经常用到的可视化方式,用于比较不同干预下皮下瘤小鼠模型的肿瘤体积变化。肿瘤生长曲线可视化主要涉及重复测量数据的可视化。在R中,我们可以通过ggplot2绘制带误差棒的折线图+散点图来实现我们的可视化需求。
图2b中带误差棒柱状图的多组统计比较可视化:这个作图思路就是先绘制不同组之间的柱状图+添加误差棒+添加抖动散点,然后添加统计注释。因为是多组之间比较,如果利用ggsignif做统计检验比较麻烦。可以事先进行统计比较,将统计结果作为一个注释数据框,然后在geom_signif函数中添加统计注释,下图是我们可视化的效果。
图2c中带误差棒柱状图的两组统计比较可视化:这个作图思路同上。
图2d中的热图:热图可视化我们之前好多期都有涉及。选择性比较多,可以用ggplot2中的geom_tile函数,也可以使用pheatmap函数,这里我们用的是complexheatmap,更加灵活。
图2e中的文本注释相关性散点图:这个作图思路也很清洗,相关性散点图+添加辅助线+文本注释,主要用到ggplot2和ggrepel包。
最后是图2f中的配对散点图:这个思路跟我们之前的配对箱线图的可视化思路基本一样。配对分析可视化中最主要的是多了配对变量,即需要指明不同分组中哪些观察值匹配。这个图的作图思路就是散点图+配对线图。
下面开启我们的复现之旅!
1 肿瘤生长曲线图 什么是肿瘤生长曲线图
肿瘤生长曲线图是一种用于描述肿瘤体积、质量或大小随时间变化的图表。这种图表通常用于研究肿瘤在不同治疗条件下的生长情况,或者用于比较不同肿瘤类型之间的生长速率。肿瘤生长曲线图可以提供关于肿瘤生长动态的重要信息,有助于研究人员和临床医生了解肿瘤的特性和应对治疗的效果。
复现代码
# Figure 2a
# 读入数据
library(readxl)
library(tidyverse)
library(ggplot2)
library(ggpubr)
library(numform)#对数字和图表进行统一格式化
# 读取Excel文件中的特定工作表
Figure_2a <- read.delim("Fig 2a.txt",header = T)
#因子化
Figure_2a$Group<-factor(Figure_2a$Group,levels = unique(Figure_2a$Group))
# 可视化
Fig_2a<-
ggplot(Figure_2a,aes(x=Day,y=Mean,color=Group,group=Group))+
geom_errorbar(aes(ymin=Mean,ymax=Mean+SEM,width=0.25),color="grey")+#添加误差棒
geom_point(size=2.5)+#点图
geom_line(linewidth=1)+#线图
labs(x="Time (d)",y=expression("Tumor volume (mm"^3*")"))+#设置坐标轴标题格式
scale_x_continuous(limits = c(8,28),breaks =seq(8,28,4),expand = c(0,0))+#设置坐标轴刻度及起始
scale_y_continuous(limits = c(0,1200),breaks = seq(0,1200,125),expand = c(0,0))+
scale_color_manual(values = c("black","#1b6292","#ff8080","#c5934e"))+
theme_classic()+
theme(legend.title = element_blank(),#不显示图例标题
legend.text = element_blank(),#不显示图例文本
legend.key.width = unit(1,"cm"),#图例宽度
legend.key.height = unit(1,"cm"),#图例高度
plot.margin = margin(r=0.5,t=0.5,unit = "cm"),#设置画板边缘大小
axis.text = element_text(color = "black"))#不显示坐标轴文本
Fig_2a
ggsave("Figure 2a.png",plot = Fig_2a,width =5,height =3.5,dpi = 600)
统计结果可以在prism里面计算出来后在AI或PS里面添加。 2 带误差棒柱状图的多组统计比较可视化 复现代码# Figure 2b
# 读入数据
Figure_2b <- read_excel("./Fig 1.xlsx", sheet = "Fig.2b",na="NA",skip = 1)[1:5,1:4]
# 宽数据转换为长数据格式
Figure_2b%>%
pivot_longer(cols = 1:4,
names_to = "Group",
values_to ="Value")->Figure_2b
# 分组标签
Group<-unique(Figure_2b$Group)
# 分组因子化
Figure_2b$Group<-factor(Figure_2b$Group,levels = unique(Figure_2b$Group),labels = c("A","B","C","D"))
# 统计分析
anova_result<-aov(Value~Group,data=Figure_2b)
# 多重比较
anno_df1<-TukeyHSD(anova_result)%>%broom::tidy()
#1. Specify the stat comparison groups
p <- "P"
anno_df1 %>% #P值格式
mutate(p_new = ifelse(adj.p.value > 0.01, c(paste("italic('P')~`=", f_num(adj.p.value,2), "`")), adj.p.value))%>%
mutate(p_new = ifelse(adj.p.value < 0.01, c(paste("italic('P')~`=", f_num(adj.p.value,3), "`")), p_new)) %>%
mutate(p_new = ifelse(adj.p.value < 0.001, c(paste("italic('P')~`", "<.001", "`")), p_new))->anno_df
# 产生P值注释的xmin和xmax参数
anno_df$group1<-substr(anno_df$contrast,3,3)
anno_df$group2<-substr(anno_df$contrast,1,1)
# 执行两两比较,使用 Bonferroni 校正
# dunn.test::dunn.test(Figure_2b$Value, g = Figure_2b$Group, method = "sidak")
# 计算不同组的均数和标准差
# 自定义函数
data_summary <- function(data, varname, groupnames){
require(plyr)
summary_func <- function(x, col){
c(mean = mean(x[[col]], na.rm=TRUE),
sd = sd(x[[col]], na.rm=TRUE))
}
data_sum<-ddply(data, groupnames, .fun=summary_func,
varname)
data_sum <- rename(data_sum, c("mean" = varname))
return(data_sum)
}
# 产生新数据框,包含每个分组的均数和标准差
Figure_2b2 <- data_summary(Figure_2b, varname="Value",
groupnames="Group")
# 可视化
Fig_2b<-
ggplot(Figure_2b2,aes(x=Group,y=Value,fill=Group))+
geom_bar(stat="identity",width = 0.6,color="black",position=position_dodge()) +#柱状图
geom_errorbar(aes(ymin=Value, ymax=Value+sd), width=.3,#添加误差棒
position=position_dodge(.9))+
geom_jitter(data=Figure_2b,aes(x=Group,y=Value),#添加散点图并设置属性
width = 0.3,height = 0.1,color="black",alpha=0.3,fill="transparent",na.rm = TRUE)+
labs(x = "", y = expression("Serum IL-17A (pg ml"^{-1}*")"))+
scale_y_continuous(limits = c(0,2500),breaks = seq(0,2500,500),expand = c(0,0))+
scale_fill_manual(values = c("black","#1b6292","#ff8080","#c5934e"),
labels=Group)+
theme_classic()+
theme(legend.position ="top",
legend.title = element_blank(),
legend.key.width = unit(1,"cm"),
legend.key.height = unit(0.3,"cm"),
legend.text = element_text(size =6),
axis.text.x = element_blank(),
axis.text.y = element_text(color = "black"),
axis.ticks.x = element_blank(),
plot.margin = margin(t=0.5,r=0.5,unit="cm"))+
guides(fill=guide_legend(nrow =2))+#设置图例显示为两行
geom_signif(annotations = anno_df[-3,]$p_new,#添加统计学结果
y_position = c(1300,2000,2200,2350,2100), #统计结果纵坐标轴对应位置
xmin=anno_df[-3,]$group1,
xmax=anno_df[-3,]$group2,textsize=8/.pt,
manual= F, parse=T, size=0.3)
Fig_2b
ggsave("Figure 2b.png",plot = Fig_2b,width =4,height =4,dpi = 600)
这里需要说明的是,作者在原文中是用了方差分析后的两两比较(Holm–Sidak’s多重比较)计算P值。 3 带误差棒柱状图的两组统计比较可视化 复现代码# Figure 2c
# 读入数据
Figure_2c<- read_excel("./Fig 1.xlsx", sheet = "Fig.2c",na="NA",skip = 1)[,1:2]
colnames(Figure_2c)<-c("A","B")
# 数据格式转换
Figure_2c%>%
pivot_longer(cols = 1:2,
names_to = "Group",
values_to = "Value")->Figure_2c
# 去除缺失值
Figure_2c<-na.omit(Figure_2c)
# 因子化
Figure_2c$Group<-factor(Figure_2c$Group,levels = unique(Figure_2c$Group))
#统计分析
#1. Specify the stat comparison groups
P <- "P"
#使用t检验(非配对样本)比较不同组间的差异
anno_df2 <- compare_means(Value~Group, data =Figure_2c, method="t.test",var.equal=TRUE,paired=F)
anno_df2 %>% #P值格式
mutate(p_new = ifelse(p > 0.01, c(paste("italic('P')~`=", f_num(p,4), "`")), p))%>%
mutate(p_new = ifelse(p < 0.01, c(paste("italic('P')~`=", f_num(p,3), "`")), p_new)) %>%
mutate(p_new = ifelse(p < 0.001, c(paste("italic('P')~`", "<.001", "`")), p_new))->anno_df2
# 产生新数据框,包含每个分组的均数和标准差
Figure_2c2 <- data_summary(Figure_2c, varname="Value",
groupnames="Group")
# 可视化
Fig_2c<-
ggplot(Figure_2c2,aes(x=Group,y=Value))+
geom_bar(stat="identity",width = 0.5,color="black",alpha=0.8,fill="grey",position=position_dodge()) +
geom_errorbar(aes(ymin=Value, ymax=Value+sd), width=.3,
position=position_dodge(.9))+
geom_jitter(data=Figure_2c,aes(x=Group,y=Value),size=2,
width = 0.3,height = 0.1,color="black",alpha=0.3,fill="transparent")+
labs(x="",y = expression("Serum IL-17A (pg ml"^{-1}*")"))+
scale_y_continuous(limits = c(0,2400),breaks = seq(0,2400,500),expand = c(0,0))+
scale_x_discrete(labels= c(expression("< 800 mm"^3), expression("> 800 mm"^3))) +
theme_classic()+
theme(axis.text = element_text(color = "black"),
axis.text.x = element_text(angle = 45,hjust =1),
plot.margin = margin(t=0.5,r=0.2,unit="cm"))+
geom_signif(annotations = anno_df2$p_new,#添加统计学结果
y_position =2250,
xmin=anno_df2$group1,
xmax=anno_df2$group2,textsize=8/.pt,
manual= F, parse=T, size=0.3)
Fig_2c
ggsave("Figure 2c.png",plot = Fig_2c,width =2.5,height =3.5,dpi = 600)
4 热图 复现代码# Figure 2d
# 读入数据
Figure_2d<- read_excel("./Fig 1.xlsx", sheet = "Fig.2d",na="NA",skip = 2)
# 重命名
colnames(Figure_2d)<-c("ID","MEL126","MEL149-2","MEL070","MEL126","MEL149-2","MEL070")
# 数据格式转换
Figure_2d%>%
t()%>%as.data.frame()->Figure_2d
# 重命名
colnames(Figure_2d)<-Figure_2d[1,]
Figure_2d<-Figure_2d[-1,]
# 将字符串转换为数值型变量
Figure_2d2<-data.frame(lapply(Figure_2d, as.numeric))
# 行名列名重命名
rownames(Figure_2d2)<-rownames(Figure_2d)
colnames(Figure_2d2)<-colnames(Figure_2d)
# 将数据框转换为矩阵
mat<-as.matrix(Figure_2d2)
# 可视化
col_fun<-colorRampPalette(colors = c("#5a89c5","white","#f8696b"))(50) #构建用于绘图的颜色
# 加载包
library(ComplexHeatmap)
library(circlize)
# 分组设置
Group=data.frame(Group=factor(rep(c("α-CTLA-4 + α-PD-1",
"α-CTLA-4 + α-PD-1 +α-IL-17A"),each=3)),row.names = rownames(Figure_2d2))
# 热图绘制
ha<-
Heatmap(mat,col = col_fun,
name = "z score",#热图名称
cluster_rows = F,cluster_columns = F,#不聚类
row_names_side = "left",#行名位置
row_names_gp = gpar(fontsize=10),#行名字体大小
column_names_gp = gpar(fontsize=10),#列名字体大小
row_title_side = "right",#行标题位置
row_title_gp = gpar(fontsize=8),#行标题字体大小
row_title_rot =0,#行标题旋转
border = T,#显示热图边框
border_gp = gpar(color="black",lwd=2),#热图边框色及宽度
rect_gp = gpar(col="grey",lwd=1.5),#热图单元格边框色及宽度
heatmap_legend_param = list(#热图图例设置
at = c(-2, 0, 2),#图例显示刻度
title = "z score",#图例标题
legend_height = unit(2, "cm"),#图例高度
direction="horizontal",#图例方向
border="black"),#图例边框颜色
row_split = Group,#行分割
row_gap = unit(0, "mm"))#行间隔宽度
pdf("Figure 2d.pdf",width =8,height =2.5)
draw(ha,heatmap_legend_side = "top")
dev.off()
5 带文本注释的相关性散点图可视化 复现代码library(ggrepel)
Figure_2e<- read_excel("./Fig 1.xlsx", sheet = "Fig.2e",na="NA",skip = 1)
Fig_2e<-
ggplot(Figure_2e,aes(x=`αPD1+αCTLA4`,y=`αPD1+αCTLA4+αIL17A`))+
geom_point(size=3.5,color="#1b6292")+
scale_y_continuous(limits = c(-1,2.5),expand = c(0,0))+
scale_x_continuous(limits = c(-1,2.5),expand = c(0,0))+
labs(x="α-CTLA-4 + α-PD-1 (z scores)",
y="α-CTLA-4 + α-PD-1 + α-IL-17A\n(z scores)")+
theme_bw()+
theme(panel.grid = element_blank())+
geom_abline(slope = 1,linetype="dashed",color="grey")+
geom_label_repel(data =Figure_2e,
aes(x=`αPD1+αCTLA4`,y=`αPD1+αCTLA4+αIL17A`, label = Marker),
box.padding = 0.2,
segment.color = NA,
label.padding = 0,
label.size =NA,
nudge_x = 0.05,
nudge_y = 0.05,
color = "black",
fill=NA,
size =3,
max.overlaps =100)
Fig_2e
ggsave("Figure 2e.png",plot = Fig_2e,width =4,height =3.5,dpi = 600)
5 配对散点图可视化
复现代码# Figure 2f
# 读入数据
Figure_2f<- read_excel("./Fig 1.xlsx", sheet = "Fig.2f",na="NA",skip = 2)[1:3,1:3]
# 重命名列名
colnames(Figure_2f)<-c("Patient","α-CTLA-4 + α-PD-1","α-CTLA-4 + α-PD-1+α-IL-17A")
# 数据格式转换
Figure_2f%>%
pivot_longer(cols = 2:3,
names_to = "Group",
values_to = "Value")->Figure_2f
# 因子化
Figure_2f$Group<-factor(Figure_2f$Group,levels = unique(Figure_2f$Group))
# 可视化
Fig_2f<-
ggplot(Figure_2f,aes(x=Group,y=Value,color=Group,group=Patient))+#按照patient分组
geom_line(color="grey")+#配对线图
geom_point(size=4)+#散点图
scale_color_manual(values = c("#1b6292","#c5934e"))+
scale_y_continuous(limits = c(min(Figure_2f$Value),80))+
labs(x="",y=expression("Delta (pg ml"^{-1}*")"))+
theme_classic()+
theme(legend.position = "top",
axis.text.x = element_blank(),
axis.text.y = element_text(color = "black"),
axis.ticks.x = element_blank())+
guides(color=guide_legend(nrow = 2))
Fig_2f
ggsave("Figure 2f.png",plot = Fig_2f,width =3,height =3.5,dpi = 600)
本次的复现就到这里了,下次再见!
图源于网络
相关推荐
R学习|使用forestploter绘制meta分析发表级森林图
R学习|使用ggplot2将你的回归分析结果可视化
R学习|个性化森林图可视化
R学习|forplo——更为灵活的森林图可视化R包
R学习|forestploter——助力实现发表级森林图绘制
R学习|一键单多因素回归分析及ggplot2可视化回归分析结果
R学习|感受ggplot2的魅力—Nature Cancer可视化结果复现
R学习|感受ggplot2的魅力—Nature Cancer可视化结果复现(二)
R学习|堆叠百分比面积图了解一下!
Python学习|Python中几行代码实现高颜值相关性热图及聚类热图可视化
R学习|感受ggplot2的魅力—ggplot2复现Nature可视化(三)
R学习|感受ggplot2的魅力—ggplot2复现Nature可视化(四)
R学习|感受ggplot2的魅力—ggplot2复现Nature可视化(五)
R学习|感受ggplot2的魅力—ggplot2复现Nature Cancer可视化(六)
微信扫一扫
关注该公众号