library(ggplot2) library(stringr) library(patchwork)
TB <- read.table("G3_all_vcf.csv") colnames(TB) <- c("Sample", "Chrom", "Loc", "Ref", "Alt") TB$SNP <- paste(TB$Ref, TB$Alt)
TB <- TB[TB$Ref %in% c("A", "G", "T", "C"),] TB <- TB[TB$Alt %in% c("A", "G", "T", "C"),]
TB$SNP <- str_replace_all(TB$SNP, "G T", "C A") TB$SNP <- str_replace_all(TB$SNP, "G A", "C T") TB$SNP <- str_replace_all(TB$SNP, "G C", "C G") TB$SNP <- str_replace_all(TB$SNP, "A G", "T C") TB$SNP <- str_replace_all(TB$SNP, "A T", "T A") TB$SNP <- str_replace_all(TB$SNP, "A C", "T G")
ggplot(TB, aes(Sample, fill= SNP)) + geom_bar(show.legend = F) + theme_bw()+ theme(axis.text.x = element_text(angle = 90,hjust = 1, vjust = .5))
TB2 <- cbind(TB,as.data.frame(str_split_fixed(TB$Sample, "_", 2))) TB2$V1 <- factor(TB2$V1, levels =c("BRAT-1", "BRAT-2", "MBT-1", "MBT-2", "AURA", "LGL")) TB2$Sample <- factor(TB2$Sample, levels =unique(TB2$Sample[order(TB2$V2)]))
P <- ggplot(TB2[TB2$V2!="Donor",], aes(Sample, fill= SNP)) + geom_bar() + theme_bw()+ theme(axis.text.x = element_text(angle = 90,hjust = 1, vjust = .5)) + facet_grid( ~V1, space = 'free', scales = 'free')
P1 <- P + coord_cartesian(y=c(0, 25000), expand = F) + theme(strip.background = element_blank(), axis.title.x = element_blank(), axis.text.x = element_blank(), axis.ticks.x = element_blank(), panel.border = element_blank(), axis.line.y.left = element_line()) P2 <- P + coord_cartesian(y=c(0, 200), expand = F)+ theme(strip.background = element_blank(), axis.title.y = element_blank(), strip.text = element_blank(), legend.position = "None", panel.border = element_blank(), axis.line.y.left = element_line(), axis.line.x.bottom = element_line())
GGlay = 'A A A B ' P1 +P2 +plot_layout(design = GGlay)
|