load(file=paste("DenisovaMat.Rda",sep="")) load(file=paste("NeanderMat.Rda",sep="")) load(file=paste("AncestMat.Rda",sep="")) load(file=paste("PopulationMat.Rda",sep="")) library(ggplot2) library(doBy) de1 <- which(DenisovaMat[,12]>0.15) de2 <- which(DenisovaMat[,35]>0.3) de <- intersect(de1,de2) ne1 <- which(NeanderMat[,12]>0.15) ne2 <- which(NeanderMat[,35]>0.3) ne <- intersect(ne1,ne2) dene <- intersect(de,ne) de <- setdiff(de,dene) ne <- setdiff(ne,dene) #### ################Denisova ASIAN####################### ASN1D <- PopulationMat[de,8] ASN2D <- PopulationMat[-de,8] l1 <- length(ASN1D) l2 <- length(ASN2D) df <- data.frame(Matching_Genome = factor( c(rep("Not Denisovan",l2),rep("Denisovan",l1)) ), proportion = c(ASN2D,ASN1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + # labs(title = "Asian Proportions in Neandertal Hapoltypes") + scale_y_continuous(breaks=c(0,2,5,7)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,8)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") name="denisovanAsian" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,2,5,7)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,8)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,2,5,7)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,8)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") dev.off() ##zoom in df <- data.frame(Matching_Genome = factor( c(rep("Not Denisovan",l2),rep("Denisovan",l1)) ), proportion = c(ASN2D,ASN1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + # labs(title = "Asian Proportions in Neandertal Hapoltypes") + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") name="denisovanAsianZ" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") dev.off() ################Denisova European####################### EUR1D <- PopulationMat[de,9] EUR2D <- PopulationMat[-de,9] l1 <- length(EUR1D) l2 <- length(EUR2D) df <- data.frame(Matching_Genome = factor( c(rep("Not Denisovan",l2),rep("Denisovan",l1)) ), proportion = c(EUR2D,EUR1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,12)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") name="denisovanEuropean" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,12)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,12)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") dev.off() ##zoom in df <- data.frame(Matching_Genome = factor( c(rep("Not Denisovan",l2),rep("Denisovan",l1)) ), proportion = c(EUR2D,EUR1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") name="denisovanEuropeanZ" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") dev.off() ################Denisova African####################### AFR1D <- PopulationMat[de,6] AFR2D <- PopulationMat[-de,6] l1 <- length(AFR1D) l2 <- length(AFR2D) df <- data.frame(Matching_Genome = factor( c(rep("Not Denisovan",l2),rep("Denisovan",l1)) ), proportion = c(AFR2D,AFR1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,6)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") name="denisovanAfrican" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,6)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,6)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") dev.off() ### zoom in df <- data.frame(Matching_Genome = factor( c(rep("Not Denisovan",l2),rep("Denisovan",l1)) ), proportion = c(AFR2D,AFR1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.35, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") name="denisovanAfricanZ" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.35, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.35, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") dev.off() ################Neandertal ASIAN####################### ASN1D <- PopulationMat[ne,8] ASN2D <- PopulationMat[-ne,8] l1 <- length(ASN1D) l2 <- length(ASN2D) df <- data.frame(Matching_Genome = factor( c(rep("Not Neandertal",l2),rep("Neandertal",l1)) ), proportion = c(ASN2D,ASN1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,9)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") name="neandertalAsian" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,9)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,9)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") dev.off() ### zoom in df <- data.frame(Matching_Genome = factor( c(rep("Not Neandertal",l2),rep("Neandertal",l1)) ), proportion = c(ASN2D,ASN1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") name="neandertalAsianZ" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") dev.off() ################Neandertal European####################### EUR1D <- PopulationMat[ne,9] EUR2D <- PopulationMat[-ne,9] l1 <- length(EUR1D) l2 <- length(EUR2D) df <- data.frame(Matching_Genome = factor( c(rep("Not Neandertal",l2),rep("Neandertal",l1)) ), proportion = c(EUR2D,EUR1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,7)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") name="neandertalEuropean" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,7)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,7)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") dev.off() ### zoom in df <- data.frame(Matching_Genome = factor( c(rep("Not Neandertal",l2),rep("Neandertal",l1)) ), proportion = c(EUR2D,EUR1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") name="neandertalEuropeanZ" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") dev.off() ################Neandertal African####################### AFR1D <- PopulationMat[ne,6] AFR2D <- PopulationMat[-ne,6] l1 <- length(AFR1D) l2 <- length(AFR2D) df <- data.frame(Matching_Genome = factor( c(rep("Not Neandertal",l2),rep("Neandertal",l1)) ), proportion = c(AFR2D,AFR1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2,3,4)) + theme(legend.position=c(.35, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,4)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") name="neandertalAfrican" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2,3,4)) + theme(legend.position=c(.35, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,4)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2,3,4)) + theme(legend.position=c(.35, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,4)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") dev.off() ### zoom in df <- data.frame(Matching_Genome = factor( c(rep("Not Neandertal",l2),rep("Neandertal",l1)) ), proportion = c(AFR2D,AFR1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.35, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") name="neandertalAfricanZ" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.35, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.35, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") dev.off() ################Archaic ASIAN####################### ASN1D <- PopulationMat[dene,8] ASN2D <- PopulationMat[-dene,8] l1 <- length(ASN1D) l2 <- length(ASN2D) df <- data.frame(Matching_Genome = factor( c(rep("Not Archaic",l2),rep("Archaic",l1)) ), proportion = c(ASN2D,ASN1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,20)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") name="archaicAsian" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,20)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,20)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") dev.off() ### zoom in df <- data.frame(Matching_Genome = factor( c(rep("Not Archaic",l2),rep("Archaic",l1)) ), proportion = c(ASN2D,ASN1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") name="archaicAsianZ" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("Asian proportion of IBD segment occurrence") dev.off() ################Archaic European####################### EUR1D <- PopulationMat[dene,9] EUR2D <- PopulationMat[-dene,9] l1 <- length(EUR1D) l2 <- length(EUR2D) df <- data.frame(Matching_Genome = factor( c(rep("Not Archaic",l2),rep("Archaic",l1)) ), proportion = c(EUR2D,EUR1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,23)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") name="archaicEuropean" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,23)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.5,23)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") dev.off() ### zoom in df <- data.frame(Matching_Genome = factor( c(rep("Not Archaic",l2),rep("Archaic",l1)) ), proportion = c(EUR2D,EUR1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") name="archaicEuropeanZ" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("European proportion of IBD segment occurrence") dev.off() ################Archaic African####################### AFR1D <- PopulationMat[dene,6] AFR2D <- PopulationMat[-dene,6] l1 <- length(AFR1D) l2 <- length(AFR2D) df <- data.frame(Matching_Genome = factor( c(rep("Not Archaic",l2),rep("Archaic",l1)) ), proportion = c(AFR2D,AFR1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,5)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") name="archaicAfrican" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,5)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + theme(legend.position=c(.5, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,5)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") dev.off() ### zoom in df <- data.frame(Matching_Genome = factor( c(rep("Not Archaic",l2),rep("Archaic",l1)) ), proportion = c(AFR2D,AFR1D)) cdf <- summaryBy(data=df, proportion ~ Matching_Genome, FUN=mean, na.rm=TRUE) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.35, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") name="archaicAfricanZ" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.35, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df, aes(x=proportion, fill=Matching_Genome)) + geom_density(alpha=.3) + geom_vline(data=cdf, aes(xintercept=proportion.mean, colour=Matching_Genome), linetype="dashed", size=1) + scale_y_continuous(breaks=c(0,1,2)) + theme(legend.position=c(.35, .5))+ theme(legend.background = element_rect(fill="gray90", size=0.3,linetype="solid",colour="black"))+ coord_cartesian(ylim = c(-0.1,2)) + ylab("Density") + xlab("African proportion of IBD segment occurrence") dev.off() ################################################################################ ################################################################################ ################################################################################ ################################################################################ lde <- length(de) dev <- rep("",lde) for (i in 1:lde) { wm <- which.max(DenisovaMat[de[i],24:27]) dev[i] <- names(wm) } lne <- length(ne) nev <- rep("",lne) for (i in 1:lne) { wm <- which.max(NeanderMat[ne[i],24:27]) nev[i] <- names(wm) } ldene <- length(dene) denev <- rep("",ldene) for (i in 1:ldene) { wm <- which.max(DenisovaMat[dene[i],24:27]) denev[i] <- names(wm) } df <- data.frame(Matching_Genome = factor( c(rep("Denisova",lde),rep("Neandertal",lne),rep("Archaic",ldene)) ), Population = c(dev,nev,denev)) ggplot(df,aes(Matching_Genome,fill=Population)) + geom_bar() + xlab("Matching Genome") + labs(title = "Population with Maximum Proportion of Archaic IBD") name="genomesMaxPopulationBar" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df,aes(Matching_Genome,fill=Population)) + geom_bar() + xlab("Matching Genome") + labs(title = "Population with Maximum Proportion of Archaic IBD") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df,aes(Matching_Genome,fill=Population)) + geom_bar() + xlab("Matching Genome") + labs(title = "Population with Maximum Proportion of Archaic IBD") dev.off() ################################################################################ ## AFR ###### lde <- length(de) dev <- rep("Without AFR",lde) no <- which(DenisovaMat[de,24]>0) dev[no] <- "With AFR" lne <- length(ne) nev <- rep("Without AFR",lne) no <- which(NeanderMat[ne,24]>0) nev[no] <- "With AFR" ldene <- length(dene) denev <- rep("Without AFR",ldene) no <- which(DenisovaMat[dene,24]>0) denev[no] <- "With AFR" df <- data.frame(Matching_Genome = factor( c(rep("Denisova",lde),rep("Neandertal",lne),rep("Archaic",ldene)) ), IBD_Segments = c(dev,nev,denev)) ggplot(df,aes(Matching_Genome,fill=IBD_Segments)) + geom_bar() + xlab("Matching Genome") + labs(title = "Archaic IBD Segments With/Without Africans") name="genomesAfricanPopulationBar" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df,aes(Matching_Genome,fill=IBD_Segments)) + geom_bar() + xlab("Matching Genome") + labs(title = "Archaic IBD Segments With/Without Africans") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df,aes(Matching_Genome,fill=IBD_Segments)) + geom_bar() + xlab("Matching Genome") + labs(title = "Archaic IBD Segments With/Without Africans") dev.off() ## AMR ###### lde <- length(de) dev <- rep("Without AMR",lde) no <- which(DenisovaMat[de,25]>0) dev[no] <- "With AMR" lne <- length(ne) nev <- rep("Without AMR",lne) no <- which(NeanderMat[ne,25]>0) nev[no] <- "With AMR" ldene <- length(dene) denev <- rep("Without AMR",ldene) no <- which(DenisovaMat[dene,25]>0) denev[no] <- "With AMR" df <- data.frame(Matching_Genome = factor( c(rep("Denisova",lde),rep("Neandertal",lne),rep("Archaic",ldene)) ), IBD_Segments = c(dev,nev,denev)) ggplot(df,aes(Matching_Genome,fill=IBD_Segments)) + geom_bar() + xlab("Matching Genome") + labs(title = "Archaic IBD Segments With/Without Admixed Americans") name="genomesAdmixedPopulationBar" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df,aes(Matching_Genome,fill=IBD_Segments)) + geom_bar() + xlab("Matching Genome") + labs(title = "Archaic IBD Segments With/Without Admixed Americans") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df,aes(Matching_Genome,fill=IBD_Segments)) + geom_bar() + xlab("Matching Genome") + labs(title = "Archaic IBD Segments With/Without Admixed Americans") dev.off() ## ASN ###### lde <- length(de) dev <- rep("Without ASN",lde) no <- which(DenisovaMat[de,26]>0) dev[no] <- "With ASN" lne <- length(ne) nev <- rep("Without ASN",lne) no <- which(NeanderMat[ne,26]>0) nev[no] <- "With ASN" ldene <- length(dene) denev <- rep("Without ASN",ldene) no <- which(DenisovaMat[dene,26]>0) denev[no] <- "With ASN" df <- data.frame(Matching_Genome = factor( c(rep("Denisova",lde),rep("Neandertal",lne),rep("Archaic",ldene)) ), IBD_Segments = c(dev,nev,denev)) ggplot(df,aes(Matching_Genome,fill=IBD_Segments)) + geom_bar() + xlab("Matching Genome") + labs(title = "Archaic IBD Segments With/Without Asians") name="genomesAsianPopulationBar" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df,aes(Matching_Genome,fill=IBD_Segments)) + geom_bar() + xlab("Matching Genome") + labs(title = "Archaic IBD Segments With/Without Asians") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df,aes(Matching_Genome,fill=IBD_Segments)) + geom_bar() + xlab("Matching Genome") + labs(title = "Archaic IBD Segments With/Without Asians") dev.off() ## EUR ###### lde <- length(de) dev <- rep("Without EUR",lde) no <- which(DenisovaMat[de,27]>0) dev[no] <- "With EUR" lne <- length(ne) nev <- rep("Without EUR",lne) no <- which(NeanderMat[ne,27]>0) nev[no] <- "With EUR" ldene <- length(dene) denev <- rep("Without EUR",ldene) no <- which(DenisovaMat[dene,27]>0) denev[no] <- "With EUR" df <- data.frame(Matching_Genome = factor( c(rep("Denisova",lde),rep("Neandertal",lne),rep("Archaic",ldene)) ), IBD_Segments = c(dev,nev,denev)) ggplot(df,aes(Matching_Genome,fill=IBD_Segments)) + geom_bar() + xlab("Matching Genome") + labs(title = "Archaic IBD Segments With/Without Europeans") name="genomesEuropeanPopulationBar" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df,aes(Matching_Genome,fill=IBD_Segments)) + geom_bar() + xlab("Matching Genome") + labs(title = "Archaic IBD Segments With/Without Europeans") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df,aes(Matching_Genome,fill=IBD_Segments)) + geom_bar() + xlab("Matching Genome") + labs(title = "Archaic IBD Segments With/Without Europeans") dev.off() ## Denisova ########### lde <- length(de) dev1 <- rep("Without",lde) no <- which(DenisovaMat[de,24]>0) dev1[no] <- "With" dev2 <- rep("Without",lde) no <- which(DenisovaMat[de,25]>0) dev2[no] <- "With" dev3 <- rep("Without",lde) no <- which(DenisovaMat[de,26]>0) dev3[no] <- "With" dev4 <- rep("Without",lde) no <- which(DenisovaMat[de,27]>0) dev4[no] <- "With" df <- data.frame(Population = factor( c(rep("AFR",lde),rep("AMR",lde),rep("ASN",lde),rep("EUR",lde)) ), With_Without = c(dev1,dev2,dev3,dev4)) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + xlab("Population") + labs(title = "Denisovan IBD Segments With/Without Populations") name="genomesDenisovaPopulationBar" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + xlab("Population") + labs(title = "Denisovan IBD Segments With/Without Populations") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + xlab("Population") + labs(title = "Denisovan IBD Segments With/Without Populations") dev.off() ## Neandertal ############# lne <- length(ne) nev1 <- rep("Without",lne) no <- which(NeanderMat[ne,24]>0) nev1[no] <- "With" nev2 <- rep("Without",lne) no <- which(NeanderMat[ne,25]>0) nev2[no] <- "With" nev3 <- rep("Without",lne) no <- which(NeanderMat[ne,26]>0) nev3[no] <- "With" nev4 <- rep("Without",lne) no <- which(NeanderMat[ne,27]>0) nev4[no] <- "With" df <- data.frame(Population = factor( c(rep("AFR",lne),rep("AMR",lne),rep("ASN",lne),rep("EUR",lne)) ), With_Without = c(nev1,nev2,nev3,nev4)) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + xlab("Population") + labs(title = "Neandertal IBD Segments With/Without Populations") name="genomesNeanderPopulationBar" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + xlab("Population") + labs(title = "Neandertal IBD Segments With/Without Populations") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + xlab("Population") + labs(title = "Neandertal IBD Segments With/Without Populations") dev.off() ## Archaic ############# ldene <- length(dene) denev1 <- rep("Without",ldene) no <- which(DenisovaMat[dene,24]>0) denev1[no] <- "With" denev2 <- rep("Without",ldene) no <- which(DenisovaMat[dene,25]>0) denev2[no] <- "With" denev3 <- rep("Without",ldene) no <- which(DenisovaMat[dene,26]>0) denev3[no] <- "With" denev4 <- rep("Without",ldene) no <- which(DenisovaMat[dene,27]>0) denev4[no] <- "With" df <- data.frame(Population = factor( c(rep("AFR",ldene),rep("AMR",ldene),rep("ASN",ldene),rep("EUR",ldene)) ), With_Without = c(denev1,denev2,denev3,denev4)) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + xlab("Population") + labs(title = "Archaic IBD Segments With/Without Populations") name="genomesArchaicPopulationBar" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + xlab("Population") + labs(title = "Archaic IBD Segments With/Without Populations") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + xlab("Population") + labs(title = "Archaic IBD Segments With/Without Populations") dev.off() lde <- length(de) ### all in one dev1 <- rep("Without",lde) no <- which(DenisovaMat[de,24]>0) dev1[no] <- "With" dev2 <- rep("Without",lde) no <- which(DenisovaMat[de,25]>0) dev2[no] <- "With" dev3 <- rep("Without",lde) no <- which(DenisovaMat[de,26]>0) dev3[no] <- "With" dev4 <- rep("Without",lde) no <- which(DenisovaMat[de,27]>0) dev4[no] <- "With" lne <- length(ne) nev1 <- rep("Without",lne) no <- which(NeanderMat[ne,24]>0) nev1[no] <- "With" nev2 <- rep("Without",lne) no <- which(NeanderMat[ne,25]>0) nev2[no] <- "With" nev3 <- rep("Without",lne) no <- which(NeanderMat[ne,26]>0) nev3[no] <- "With" nev4 <- rep("Without",lne) no <- which(NeanderMat[ne,27]>0) nev4[no] <- "With" ldene <- length(dene) denev1 <- rep("Without",ldene) no <- which(DenisovaMat[dene,24]>0) denev1[no] <- "With" denev2 <- rep("Without",ldene) no <- which(DenisovaMat[dene,25]>0) denev2[no] <- "With" denev3 <- rep("Without",ldene) no <- which(DenisovaMat[dene,26]>0) denev3[no] <- "With" denev4 <- rep("Without",ldene) no <- which(DenisovaMat[dene,27]>0) denev4[no] <- "With" df <- data.frame(Population = factor( c(rep("D-AFR",lde),rep("D-AMR",lde),rep("D-ASN",lde),rep("D-EUR",lde),rep("N-AFR",lne),rep("N-AMR",lne),rep("N-ASN",lne),rep("N-EUR",lne),rep("A-AFR",ldene),rep("A-AMR",ldene),rep("A-ASN",ldene),rep("A-EUR",ldene) ) ), With_Without = c(dev1,dev2,dev3,dev4,nev1,nev2,nev3,nev4,denev1,denev2,denev3,denev4)) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + scale_x_discrete(breaks=c("D-AFR","D-AMR","D-ASN","D-EUR","N-AFR","N-AMR","N-ASN","N-EUR","A-AFR","A-AMR","A-ASN","A-EUR"),labels=c("AFR","AMR","ASN","EUR","AFR","AMR","ASN","EUR","AFR","AMR","ASN","EUR")) + annotate("text",x=6.5,y=4200,label="Denisovan") + annotate("rect",xmin=0.5,xmax=4.5,ymin=-0.1,ymax=6000,alpha=0,colour="black") + annotate("text",x=10.5,y=8400,label="Neandertal") + annotate("rect",xmin=4.5,xmax=8.5,ymin=-0.1,ymax=4500,alpha=0,colour="black") + annotate("text",x=2.5,y=5800,label="Archaic") + annotate("rect",xmin=8.5,xmax=12.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + xlab("Population") + labs(title = "Archaic IBD Segments With/Without Populations") name="genomesAllPopulationBar" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + scale_x_discrete(breaks=c("D-AFR","D-AMR","D-ASN","D-EUR","N-AFR","N-AMR","N-ASN","N-EUR","A-AFR","A-AMR","A-ASN","A-EUR"),labels=c("AFR","AMR","ASN","EUR","AFR","AMR","ASN","EUR","AFR","AMR","ASN","EUR")) + annotate("text",x=6.5,y=4200,label="Denisovan") + annotate("rect",xmin=0.5,xmax=4.5,ymin=-0.1,ymax=6000,alpha=0,colour="black") + annotate("text",x=10.5,y=8400,label="Neandertal") + annotate("rect",xmin=4.5,xmax=8.5,ymin=-0.1,ymax=4500,alpha=0,colour="black") + annotate("text",x=2.5,y=5800,label="Archaic") + annotate("rect",xmin=8.5,xmax=12.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + xlab("Population") + labs(title = "Archaic IBD Segments With/Without Populations") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + scale_x_discrete(breaks=c("D-AFR","D-AMR","D-ASN","D-EUR","N-AFR","N-AMR","N-ASN","N-EUR","A-AFR","A-AMR","A-ASN","A-EUR"),labels=c("AFR","AMR","ASN","EUR","AFR","AMR","ASN","EUR","AFR","AMR","ASN","EUR")) + annotate("text",x=6.5,y=4200,label="Denisovan") + annotate("rect",xmin=0.5,xmax=4.5,ymin=-0.1,ymax=6000,alpha=0,colour="black") + annotate("text",x=10.5,y=8400,label="Neandertal") + annotate("rect",xmin=4.5,xmax=8.5,ymin=-0.1,ymax=4500,alpha=0,colour="black") + annotate("text",x=2.5,y=5800,label="Archaic") + annotate("rect",xmin=8.5,xmax=12.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + xlab("Population") + labs(title = "Archaic IBD Segments With/Without Populations") dev.off() df <- data.frame(Population = factor( c(rep("AFR-D",lde),rep("AFR-N",lne),rep("AFR-A",ldene),rep("AMR-D",lde),rep("AMR-N",lne),rep("AMR-A",ldene),rep("ASN-D",lde),rep("ASN-N",lne),rep("ASN-A",ldene),rep("EUR-D",lde),rep("EUR-N",lne),rep("EUR-A",ldene) ) ), With_Without = c(dev1,nev1,denev1,dev2,nev2,denev2,dev3,nev3,denev3,dev4,nev4,denev4)) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + scale_x_discrete(breaks=c("AFR-D","AFR-N","AFR-A","AMR-D","AMR-N","AMR-A","ASN-D","ASN-N","ASN-A","EUR-D","EUR-N","EUR-A"),labels=c("Den","Nea","Arc","Den","Nea","Arc","Den","Nea","Arc","Den","Nea","Arc")) + annotate("text",x=2,y=8400,label="African") + annotate("rect",xmin=0.5,xmax=3.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + annotate("text",x=5,y=8400,label="Admixed") + annotate("rect",xmin=3.5,xmax=6.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + annotate("text",x=8,y=8400,label="Asian") + annotate("rect",xmin=6.5,xmax=9.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + annotate("text",x=11,y=8400,label="European") + annotate("rect",xmin=9.5,xmax=12.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + xlab("Population") + labs(title = "Archaic IBD Segments With/Without Populations") name="genomesAllArchaicBar" pdf(paste(name,".pdf",sep=""),width=8) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + scale_x_discrete(breaks=c("AFR-D","AFR-N","AFR-A","AMR-D","AMR-N","AMR-A","ASN-D","ASN-N","ASN-A","EUR-D","EUR-N","EUR-A"),labels=c("Den","Nea","Arc","Den","Nea","Arc","Den","Nea","Arc","Den","Nea","Arc")) + annotate("text",x=2,y=8400,label="African") + annotate("rect",xmin=0.5,xmax=3.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + annotate("text",x=5,y=8400,label="Admixed") + annotate("rect",xmin=3.5,xmax=6.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + annotate("text",x=8,y=8400,label="Asian") + annotate("rect",xmin=6.5,xmax=9.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + annotate("text",x=11,y=8400,label="European") + annotate("rect",xmin=9.5,xmax=12.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + xlab("Population") + labs(title = "Archaic IBD Segments With/Without Populations") dev.off() xfig(paste(name,".fig",sep=""),width=8) ggplot(df,aes(Population,fill= With_Without)) + geom_bar() + scale_x_discrete(breaks=c("AFR-D","AFR-N","AFR-A","AMR-D","AMR-N","AMR-A","ASN-D","ASN-N","ASN-A","EUR-D","EUR-N","EUR-A"),labels=c("Den","Nea","Arc","Den","Nea","Arc","Den","Nea","Arc","Den","Nea","Arc")) + annotate("text",x=2,y=8400,label="African") + annotate("rect",xmin=0.5,xmax=3.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + annotate("text",x=5,y=8400,label="Admixed") + annotate("rect",xmin=3.5,xmax=6.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + annotate("text",x=8,y=8400,label="Asian") + annotate("rect",xmin=6.5,xmax=9.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + annotate("text",x=11,y=8400,label="European") + annotate("rect",xmin=9.5,xmax=12.5,ymin=-0.1,ymax=8600,alpha=0,colour="black") + xlab("Population") + labs(title = "Archaic IBD Segments With/Without Populations") dev.off()