[R] colors in violin plot, ggplot2

Monica Pisica pisicandru at hotmail.com
Tue Apr 1 04:43:15 CEST 2014


I am using ggplot and geom_violin to build a violin plot of some with only 2 categories. All is good except that I cannot set up the colors I want or the violin plots. Either I have same color for both my categories or colors from probably rainbow(2), which are red and blue. What if I want brown and forestgreen. How do I do it?

so my code follows:

p <- ggplot(x1, aes(Location, aer_m_GPS , fill=factor(Location), colour=factor(Location)))

p1 <- p+geom_violin(alpha=0.3, width=1, trim = FALSE, scale = "width", adjust = 0.5) + geom_boxplot(width=0.2, outlier.colour="red", notch = FALSE, notchwidth = .5, alpha = 0.5, colour = "grey50")


This will plot the violin plot with boxplot superimposed on it, both with color red and blue. I hope to get brown and forestgreen.

Thanks for any advice,


More information about the R-help mailing list