16 Dot Plots
(CH slack: 28th Dec 2020- 29th Dec 2020)
(CH slack: 28th Dec 2020- 29th Dec 2020)
location on server: /space/chen-syn01/1/data/cinliu/plots/16dot_plot
Data given: /space/chen-syn01/1/data/chen/gwas_gclust/genesis/ABCD/genesis_pcs.text
CH :
Can you help plotting a composite plot of every pair of PCs using this spreadsheet?
"/space/chen-syn01/1/data/chen/gwas_gclust/genesis/ABCD/genesis_pcs.text"
There are 32 PCs so there will be 16 pairs. One composite plot with 16 plots inside.
Sample graph provided
qplot(genesis$PC1,genesis$PC2,col=genesis$GAF4)
rm(list=ls())
library(ggplot2)
library(gridExtra)
setwd("/Users/nini/Desktop/2020lab/plots/CH/")
import the two .txt files
## Read and adjust data
score = read.table(paste0(DDir, "PRS_1e5_positive.txt"), header=T) # loading file with p-value < 1e5
score=score[complete.cases(score),] # remove rows with NAs
score_s = score # make a copy of the data
score_s[,18:76] = scale(score[,18:76],center=T,scale=T) # over-write the data copy with standardized PRS (overall mean = 0 and SD = 1)
summary(score_s)
scp data from "/space/chen-syn01/1/data/chen/gwas_gclust/genesis/ABCD/genesis_pcs.text"
This data has 9136 rows and 34 columns
PC goes all the way from PC1 - PC32
We are interested in plotting the PCs in pairs, this way in the end we should end up with 16 graphs.
#scp data from "/space/chen-syn01/1/data/chen/gwas_gclust/genesis/ABCD/genesis_pcs.text"
genesis <- read.csv("~/Desktop/2020lab/plots/CH/genesis_pcs.text", sep="")
We will begin with make 16 indivisual plots first using the qplot() function.
#making the plots
p1 <- qplot(genesis$PC1,genesis$PC2,col=genesis$GAF4)
p2 <- qplot(genesis$PC3,genesis$PC4,col=genesis$GAF4)
p3 <- qplot(genesis$PC5,genesis$PC6,col=genesis$GAF4)
p4 <- qplot(genesis$PC7,genesis$PC8,col=genesis$GAF4)
p5 <- qplot(genesis$PC9,genesis$PC10,col=genesis$GAF4)
p6 <- qplot(genesis$PC11,genesis$PC12,col=genesis$GAF4)
p7 <- qplot(genesis$PC13,genesis$PC14,col=genesis$GAF4)
p8 <- qplot(genesis$PC15,genesis$PC16,col=genesis$GAF4)
p9 <- qplot(genesis$PC17,genesis$PC18,col=genesis$GAF4)
p10 <- qplot(genesis$PC19,genesis$PC20,col=genesis$GAF4)
p11 <- qplot(genesis$PC21,genesis$PC22,col=genesis$GAF4)
p12 <- qplot(genesis$PC23,genesis$PC24,col=genesis$GAF4)
p13 <- qplot(genesis$PC25,genesis$PC26,col=genesis$GAF4)
p14 <- qplot(genesis$PC27,genesis$PC28,col=genesis$GAF4)
p15 <- qplot(genesis$PC29,genesis$PC30,col=genesis$GAF4)
p16 <- qplot(genesis$PC31,genesis$PC32,col=genesis$GAF4)
Arrange the 16 plots in Grid view format so we can see all of them on one page
grid.arrange(p1,p2,p3,p4,p5,p6,p7,p8,p10,p11,p12,p13,p14,p15,p16,p17, nrow = 4)
g <- arrangeGrob(p1,p2,p3,p4,p5,p6,p7,p8,p10,p11,p12,p13,p14,p15,p16,p17, nrow = 4) #generates graphs
ggsave(file="composite.tiff", g, width = 39, height = 39, units = "cm") #saves graphs
composite_plots.R
rm(list=ls())
library(ggplot2)
library(gridExtra)
setwd("/Users/nini/Desktop/2020lab/plots/CH/")
genesis <- read.csv("~/Desktop/2020lab/plots/CH/genesis_pcs.text", sep="")
#scp data from "/space/chen-syn01/1/data/chen/gwas_gclust/genesis/ABCD/genesis_pcs.text"
#making the plots
p1 <- qplot(genesis$PC1,genesis$PC2,col=genesis$GAF4)
p2 <- qplot(genesis$PC3,genesis$PC4,col=genesis$GAF4)
p3 <- qplot(genesis$PC5,genesis$PC6,col=genesis$GAF4)
p4 <- qplot(genesis$PC7,genesis$PC8,col=genesis$GAF4)
p5 <- qplot(genesis$PC9,genesis$PC10,col=genesis$GAF4)
p6 <- qplot(genesis$PC11,genesis$PC12,col=genesis$GAF4)
p7 <- qplot(genesis$PC13,genesis$PC14,col=genesis$GAF4)
p8 <- qplot(genesis$PC15,genesis$PC16,col=genesis$GAF4)
p9 <- qplot(genesis$PC17,genesis$PC18,col=genesis$GAF4)
p10 <- qplot(genesis$PC19,genesis$PC20,col=genesis$GAF4)
p11 <- qplot(genesis$PC21,genesis$PC22,col=genesis$GAF4)
p12 <- qplot(genesis$PC23,genesis$PC24,col=genesis$GAF4)
p13 <- qplot(genesis$PC25,genesis$PC26,col=genesis$GAF4)
p14 <- qplot(genesis$PC27,genesis$PC28,col=genesis$GAF4)
p15 <- qplot(genesis$PC29,genesis$PC30,col=genesis$GAF4)
p16 <- qplot(genesis$PC31,genesis$PC32,col=genesis$GAF4)
grid.arrange(p1,p2,p3,p4,p5,p6,p7,p8,p10,p11,p12,p13,p14,p15,p16,p17, nrow = 4)
g <- arrangeGrob(p1,p2,p3,p4,p5,p6,p7,p8,p10,p11,p12,p13,p14,p15,p16,p17, nrow = 4) #generates graphs
ggsave(file="composite.tiff", g, width = 39, height = 39, units = "cm") #saves graphs