location on server: /space/chen-syn01/1/data/cinliu/plots/barplots/barplot_with_star
I would want a bar plot for each file, where the y-axis is "Region", the x-axis is "r", and the bars are coloured by "Measure". The bars should be sorted from largest to smallest r-value.
Then for the "posbetas_" and "negbetas_*" files, I would want to indicate somehow the bars that have a pval<0.0025, and those with a pval<0.05. For instance, maybe two asterisks marking pval<0.0025, and one asterisk for pval<0.05? This wouldn't apply for the "allbetas_*" file because they are all significantly correlated.
What I did:
install ggplot2 and ggsignif
input the data
make geom_bar() to make a basic bar plot
y= r
x= region reordered by r
fill = measurement
use coord_flip() to make sure the x and y axis is reversed
specify color (she wants blue and dark blue)
Adding significant * to the plot - you basicall add a new column to the data, this new column will literly add a * or ** in that collumn if the value is significant.
In the example here dataP$pval less then 0.05 will get one star, less then 0.0025 will get 2 stars. We then pull them out as subset data.
#stars
dataP$star <- ""
dataP$star[dataP$pval<0.05] <- "*"
dataP$star[dataP$pval<0.0025] <- "**"
pfivesub <- subset.data.frame(dataP,star == "*")
ptwosub <- subset.data.frame(dataP,star == "**")
And then once you have then stars given. Label them in the plot
geom_text(data = fivesub, label = "*", size =15) +
geom_text(data = twosub, label = "**", size =15) +
output with ggsave