email title: "updating pie charts to bars for gwas paper" - Carolina
July 15th 2020 -July 16th 2020
Project location on server: /space/chen-syn01/1/data/cinliu/plots/bar_and_pie_plots
Initial instructions:
would you be able to modify this R code I wrote that generates pie charts, and instead format the figure so it is a vertical bar instead?
Initial files attached: 1 sample plot, sample code, data in .sumstats
Note: Access to this folder is no longer available
Converted sample image:
Folder for image:
Note: Access to this folder is no longer available
Barplot_PNGoutput.R
####pie chartsrm(list=ls()) #change your working directory heresetwd("/Users/niniliu/Desktop/2020lab/carolina plots/piechart/") library(data.table)library(psych)library(tableone)library(tidyverse)library(Hmisc)library(gtools)library(knitr)library(kableExtra)library(ggplot)library(dplyr)library(gridExtra) #load annotation filesnps_annot_bh <- fread(file="annotstats_concat_bh.sumstats", stringsAsFactors=FALSE, data.table=FALSE)
#####pie graph for annotation of SNPs #add labels for pie chartssnps_annot_bh$lbls<-paste(snps_annot_bh$annot,round((snps_annot_bh$prop*100),2),sep=" ") #for loop to create a pie graph for each cortical phenotype#Work in progress:#this for loop saves each pie graph individually, but doesn't save all of the graphs individually in R, which is what I would need if I wanted to create a grid of figures in R#also, for some reason the first "q" plot is not generated becauseI get a warning of "Removed 11 rows containing missing values (position_stack)." However looking at q, it is populated with the right data.#once I run "p" though, using the data in "q", then the plots are ok...I'm wondering if it is because ggplot doesn't like that I "filtered" the variables in the command regions<-unique(snps_annot_bh$Region_forpaper)p<-list()plots <- list()attach(mtcars) for (i in regions) { filter<-grep(i,snps_annot_bh$Region_forpaper) q<-ggplot(snps_annot_bh[filter,], aes(x = "", y = prop[filter], fill = lbls[filter])) + geom_bar(width=0.1, stat = "identity", color = "white")+ theme_void() idx<-match(i,regions) p<-ggplot(q$data,aes(x="",y=q$data$prop,fill=q$data$lbls)) + geom_bar(width=0.4, stat = "identity", color = "white", size=0)+ theme_void()+ theme(legend.position = "none") p +scale_fill_manual(name = i, values=c("#5c8001", "#7cb518", "#f4ac32", "#e46211", "#f18987", "#9b6371", "#465775", "#8780b3","#c7a8f0", "#0eb1d2", "#092d34")) #replace the legend title with name of phenotype #save all ggsave(paste0("PNG",i,"_bargraph.png"),width=1,height=4)}