本期内容为[跟着NC学作图]--散点图
文章题目:
感兴趣的可以自己去看!
代码部分:
- 导入数据,文章中的代码是比较复杂的,那么我自己就使用画图前的数据。
> nb_Omicron_Delta
sample nb_Delta nb_Omicron ratio_Delta ratio_Omicron ID proto ext Delta Coinf
22PlCoInf-MIDV2xEMAGx0x100_S373 0 47 0 1 22PlCoInf-MIDV2xEMAGx0x100 MIDNIGHT V2 EMAG 0 FALSE
22PlCoInf-MIDV2xEMAGx100x0_S384 25 0 1 0 22PlCoInf-MIDV2xEMAGx100x0 MIDNIGHT V2 EMAG 100 FALSE
22PlCoInf-MIDV2xEMAGx10x90_S374 24 47 0.96 1 22PlCoInf-MIDV2xEMAGx10x90 MIDNIGHT V2 EMAG 10 TRUE
22PlCoInf-MIDV2xEMAGx20x80_S375 25 46 1 0.978723404 22PlCoInf-MIDV2xEMAGx20x80 MIDNIGHT V2 EMAG 20 TRUE
22PlCoInf-MIDV2xEMAGx30x70_S376 25 44 1 0.936170213 22PlCoInf-MIDV2xEMAGx30x70 MIDNIGHT V2 EMAG 30 TRUE
22PlCoInf-MIDV2xEMAGx40x60_S377 25 44 1 0.936170213 22PlCoInf-MIDV2xEMAGx40x60 MIDNIGHT V2 EMAG 40 TRUE
sample nb_Delta nb_Omicron ratio_Delta ratio_Omicron ID proto ext Delta Coinf median_Delta IQR_Delta median_Omicron IQR_Omicron
22PlCoInf-MIDV2xEMAGx0x100_S373 0 47 0 1 22PlCoInf-MIDV2xEMAGx0x100 MIDNIGHT V2 EMAG 0 FALSE 0 0 99 1.5
22PlCoInf-MIDV2xEMAGx100x0_S384 25 0 1 0 22PlCoInf-MIDV2xEMAGx100x0 MIDNIGHT V2 EMAG 100 FALSE 99 0 0 0
22PlCoInf-MIDV2xEMAGx10x90_S374 24 47 0.96 1 22PlCoInf-MIDV2xEMAGx10x90 MIDNIGHT V2 EMAG 10 TRUE 33 11.5 64 10
22PlCoInf-MIDV2xEMAGx20x80_S375 25 46 1 0.978723404 22PlCoInf-MIDV2xEMAGx20x80 MIDNIGHT V2 EMAG 20 TRUE 53 12 43.5 18
22PlCoInf-MIDV2xEMAGx30x70_S376 25 44 1 0.936170213 22PlCoInf-MIDV2xEMAGx30x70 MIDNIGHT V2 EMAG 30 TRUE 67 13 29.5 13.25
22PlCoInf-MIDV2xEMAGx40x60_S377 25 44 1 0.936170213 22PlCoInf-MIDV2xEMAGx40x60 MIDNIGHT V2 EMAG 40 TRUE 70 10 26 10.5
22PlCoInf-MIDV2xEMAGx50x50_S378 25 46 1 0.978723404 22PlCoInf-MIDV2xEMAGx50x50 MIDNIGHT V2 EMAG 50 TRUE 78 5 18.5 8.75
- Plot A
nb_Omicron_Delta$Delta = as.numeric(nb_Omicron_Delta$Delta)
p1 <- ggplot(data=nb_Omicron_Delta, aes(x=ratio_Omicron, y=ratio_Delta ,colour=Delta))
p1 <- p1 +
geom_point(aes(colour=Delta,shape=Coinf),alpha=0.9) +
facet_grid(.~proto) +
ylab("Delta-specific mutations detection rate") + xlab("Omicron-specific mutations detection rate") +
scale_color_gradient2(low = "steelblue1", mid = "cyan4", high = "tomato",
breaks=c(0,10,20,30,40,50,60,70,80,90,100), midpoint = 50,
name = "Delta:Omicron", labels = c("0:100","10:90","20:80", "30:70","40:60","50:50","60:40","70:30", "80:20","90:10","100:0")) +
scale_shape(name = "Experimental\nCoinfection") +
geom_vline(xintercept = 0.25,linetype = "dotted", alpha = 0.5, inherit.aes = FALSE) +
geom_hline(yintercept = 0.90,linetype = "dotted", alpha = 0.5, inherit.aes = FALSE) +
theme_bw()
- Plot B
p2 <- ggplot(data=table_MAF, aes(x=Delta, y=median_Delta))
p2 <- p2 +
geom_smooth(color="grey", fill="grey", linetype="blank") +
geom_point(aes(colour=Delta,shape=Coinf)) +
facet_grid(.~proto) +
ylab("Measured Frequency (%)") + xlab("Expected Frequency (%)") +
geom_abline(intercept = 0, slope = 1,linetype = "dotted", alpha = 0.5, inherit.aes = FALSE) +
scale_color_gradient2(low = "steelblue1", mid = "cyan4", high = "tomato",
breaks=c(0,10,20,30,40,50,60,70,80,90,100), midpoint = 50,
name = "Delta:Omicron", labels = c("0:100","10:90","20:80", "30:70","40:60","50:50","60:40","70:30", "80:20","90:10","100:0")) +
scale_shape(name = "Experimental\nCoinfection") +
theme_bw()
- Plot C
plot_AF_fig1C <- function(vcf_file,annot_file, ncol=11) {
require(data.table)
library(ggplot2)
annot=annot_file
##########################
### annotate vcf
##########################
vcf=vcf_file
vcf$VOC <- sapply(vcf$nt_mut, function(x) ifelse(is.element(x,annot$nt_mut),annot$var[x==annot$nt_mut],NA)) ## For each variant, determine whether it is Delta- or OMICRON-specific
vcf$proto = sapply(vcf$ID , function(x) strsplit(x,"x")[[1]][1])
vcf$proto = gsub("MID","MIDNIGHT ",vcf$proto)
vcf$proto = gsub("V4","ARTIC V4",vcf$proto)
vcf$proto = gsub("V41","V4.1",vcf$proto)
vcf$proto = gsub("MIDNIGHT $","MIDNIGHT V1",vcf$proto)
vcf$proto = factor(vcf$proto,levels=c("MIDNIGHT V1","MIDNIGHT V2","ARTIC V4","ARTIC V4.1"))
########## plot AF bars of DELTA-specific and/or OMICRON-specific mutations
vcfDO = vcf[!is.na(vcf$VOC),]
# Plot
p <- ggplot(data=vcfDO, aes(x=nt_pos, y=af, group = sample ))
p <- p +
geom_bar(aes(fill = VOC), stat="identity") +
geom_point(data=vcfDO[vcfDO$af>50,], aes(x=nt_pos, y=af, group = sample,color = VOC),size=1,alpha=0.8)+
facet_wrap(.~proto, ncol=ncol) +
ylab("Mutation frequency (%)") + xlab("Nucleotide position") +
scale_color_manual(values=c("tomato","darkgrey","steelblue1"),name = "Mutations in\nconsensus", labels = c("Delta-specific", "shared", "Omicron-specific")) +
scale_fill_manual(values=c("tomato","darkgrey","steelblue1"),name = "Mutations", labels = c("Delta-specific", "shared", "Omicron-specific")) +
geom_hline(yintercept = 50,linetype = "dotted", alpha = 0.5, inherit.aes = FALSE) +
theme_bw() + theme( axis.text.x = element_text(angle=45, size=8,hjust =1, vjust=1)) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
return(p)
}
- 合并图
plot_grid(p1, p2,p3, ncol = 1,labels = c("A","B","C"), align = 'v',axis = "rl",rel_heights=c(1,1,1.1))
ggsave("Fig1.pdf",width = 10 ,height=9 )
ggsave("Fig1.png",width = 10 ,height=9)
往期文章(总汇)
01-[R语言可视化-精美图形绘制系列]--精美火山图
02-R语言可视化-精美图形绘制系列--柱状图
03-R语言可视化-精美图形绘制系列--功能富集分析
04-R语言可视化-精美图形绘制系列—多组GO富集可视化
05-[R语言可视化-精美图形绘制系列--堆积图]
06-[R语言可视化-精美图形绘制系列--组间相关性分析]
07-[R语言可视化-精美图形绘制系列]--Mental分析
08-[R语言可视化-精美图形绘制系列--复杂热图+两图渐变连线]-【转载】
09-[R语言可视化-精美图形绘制系列--桑基图(Sankey)]
10-[R语言可视化-精美图形绘制系列--柱状图误差线标记]
11-跟着NC学作图 | 柱状图与相关性图
12-[R语言可视化-精美图形绘制系列--GO、KEGG富集通路关联图]
13-[跟着“基迪奥生物学”作图]--截断图
14-[R语言可视化-精美图形绘制系列]--显著性箱线图
14-2[R语言可视化]--箱线图不同的画法及参数设置 | 学习笔记
15-[R语言可视化-精美图形绘制系列]--组内相关性分析
16-[R语言可视化-精美图形绘制系列]--主成分分析(PCA)
017-[跟着NC学作图]--箱线图(一个函数获得Mean、SD、P值)
019-[跟着NC学作图]--生存分析(Survival analysis)