3in1 barplot
email title: "R plot for brain imaging genetics data"
Email with CH (gmail) April 17th 2020
Email with CH (gmail) April 17th 2020
Location on server: /space/chen-syn01/1/data/cinliu/plots/barplots/3in1_plot_edit1
Initial instructions:
Here are an initial R script for plotting and three plots generated by the script. It'd be great to have your help to combine the three plots side-by-side into one single plot.
What I did:
change working directory and file locations
name each plot a specific name
turn off x labs for plot 2 and 3, turn off axis ticks
install 'grid' package - library(grid)
using pushViewport() function in gird to put them all on one page
export by hand using the Rstudio export
bold parts are the major edits
library(ggplot2)
library(grid)
rm(list=ls())
setwd('/Users/niniliu/Desktop/2020lab/plots/')
DDir='/Users/niniliu/Desktop/2020lab/plots/'
data=read.table(paste0(DDir,'summary.txt'), h=T)
# pull out the catgroy and its sd - Nini
pi=data[,2:3]
s=data[,4:5]
hsq=data[,6:7]
#par(mfrow=c(1,3)) # modify to make a composite plot
piplot <- ggplot(data, aes(fill=pi, y=pi, x= region)) +
geom_errorbar(aes(ymin=pi-pi_sd, ymax=pi+pi_sd), width=.2,
position=position_dodge(0.7)) +
geom_bar(position="dodge",stat="identity",width=0.7) + coord_flip() +
ggtitle("polygenicity") +
theme(legend.position = "bottom",
legend.text = element_text(angle = 0, hjust = 1))
splot <- ggplot(s, aes(fill=s, y=s, x=data$region)) +
geom_errorbar(aes(ymin=s-s_sd, ymax=s+s_sd), width=.2,
position=position_dodge(0.7)) +
geom_bar(position="dodge",stat="identity",width=0.7) + coord_flip() +
ggtitle("selection") +
theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
legend.position = "bottom",
legend.text = element_text(angle = 0, hjust = 1)) +
labs( x= NULL)
hsqplot <- ggplot(hsq, aes(fill=hsq, y=hsq, x=data$region)) +
geom_errorbar(aes(ymin=hsq-hsq_sd, ymax=hsq+hsq_sd), width=.2,
position=position_dodge(0.7)) +
geom_bar(position="dodge",stat="identity",width=0.7) + coord_flip() +
ggtitle("heritability")+
theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
legend.position = "bottom",
legend.text = element_text(angle = 0, hjust = 1)) +
labs( x= NULL)
#assemble
grid.newpage()
pushViewport(viewport(layout =grid.layout(1, 3, widths = c(2, 1, 1))))
#put in plots
print(piplot, vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
print(splot, vp = viewport(layout.pos.row = 1, layout.pos.col = 2))
print(hsqplot, vp = viewport(layout.pos.row = 1, layout.pos.col = 3))
#exporting manually as 1025x825 to keep all plots in one image
Tools not used in final but looked at during this project
Final image: