本期內(nèi)容為[跟著NC學(xué)作圖]--散點圖
文章題目:
感興趣的可以自己去看!
代碼部分:
- 導(dǎo)入數(shù)據(jù),文章中的代碼是比較復(fù)雜的,那么我自己就使用畫圖前的數(shù)據(jù)。
> 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語言可視化-精美圖形繪制系列--組間相關(guān)性分析]
07-[R語言可視化-精美圖形繪制系列]--Mental分析
08-[R語言可視化-精美圖形繪制系列--復(fù)雜熱圖+兩圖漸變連線]-【轉(zhuǎn)載】
09-[R語言可視化-精美圖形繪制系列--杀钙瑁基圖(Sankey)]
10-[R語言可視化-精美圖形繪制系列--柱狀圖誤差線標記]
11-跟著NC學(xué)作圖 | 柱狀圖與相關(guān)性圖
12-[R語言可視化-精美圖形繪制系列--GO、KEGG富集通路關(guān)聯(lián)圖]
13-[跟著“基迪奧生物學(xué)”作圖]--截斷圖
14-[R語言可視化-精美圖形繪制系列]--顯著性箱線圖
14-2[R語言可視化]--箱線圖不同的畫法及參數(shù)設(shè)置 | 學(xué)習(xí)筆記
15-[R語言可視化-精美圖形繪制系列]--組內(nèi)相關(guān)性分析
16-[R語言可視化-精美圖形繪制系列]--主成分分析(PCA)
017-[跟著NC學(xué)作圖]--箱線圖(一個函數(shù)獲得Mean许昨、SD懂盐、P值)
019-[跟著NC學(xué)作圖]--生存分析(Survival analysis)