library(ggplot2) library(viridis) library(viridisLite) library(tidyverse) ## Check working directory getwd() ## Set working directory setwd("C:/Users/bblake/OneDrive - Environmental Protection Agency (EPA)/Profile/Documents/NTP TGMX/TGMX new/CSV") ## Read in data x<-read.csv("Significant NES hallmark pathway maternal fetal liver.csv", header=T) ## Check data structure str(x) x$tissue<-as.factor(as.character(x$tissue)) x$dose<-as.factor(as.character(x$dose)) x$pathway<-as.factor(as.character(x$pathway)) x$tissue<-factor(x$tissue, levels=c("Maternal liver","Fetal liver")) x$dose<-factor(x$dose, levels=c("1 mg/kg PFOA","5 mg/kg PFOA","2 mg/kg GenX","10 mg/kg GenX")) x$pathway <- reorder(x$pathway, x$n.sig.all) x$significance <- 1/x$p p<-ggplot(x, aes(x=dose, y=pathway, colour=p, size=NES)) + theme_bw()+ geom_point() + facet_grid(~tissue)+ scale_colour_viridis(direction=-1, begin = 0.05,end = 0.95,option="D") #labs(x="Group", y="Pathway", colour="NES", size="p value")+ #scale_size(trans = 'reverse') p p<-ggplot(x, aes(x=pathway, y=NES, color=NES, size=p)) + theme_bw()+ geom_point() + facet_grid(tissue~dose)+ coord_flip()+ geom_hline(yintercept=0, color="gray", linetype="dashed")+ scale_colour_viridis(direction=1, begin = 0.05,end = 0.95,option="D")+ labs(y="Normalized Enrichment Score", colour="NES", size="p value")+ scale_size(trans="reverse") p tiff("Hallmark Pathway NES.tiff", units="in", width=7.75, height=7.5, res=300) x$n.sig.all<-as.factor(as.numeric(x$n.sig.all)) p<-ggplot(x, aes(x=pathway, y=NES, color=n.sig.all, size=log(p))) + theme_bw()+ geom_point() + facet_grid(tissue~dose)+ coord_flip()+ geom_hline(yintercept=0, color="gray", linetype="dashed")+ scale_colour_viridis(direction=1, begin = 0 ,end = 0.94, option="D", discrete=TRUE)+ labs(y="Normalized Enrichment Score", x="Hallmark Pathway", size="log10(p value)")+ scale_size(trans="reverse") p dev.off()