Hi Denis, Thank you so much. This is exactly what i needed. I am not telling you how much time i wasted to change default colors for fill and colour, coming up with pretty weird ideas, non working, of course. Thanks again, Monica > Date: Tue, 1 Apr 2014 02:23:08 -0700 > Subject: Re: [R] colors in violin plot, ggplot2 > From: djmu...@gmail.com > To: pisican...@hotmail.com > > Hi: > > Your example is not reproducible in the absence of data, but this is > an opportunity to show you how to make one. I'm using the built-in > mtcars data set for illustration. Assuming that all you want is to > change the default color/fill scheme, here's one way to do it. > > library(ggplot2) > > mtcars1 <- mtcars # make a copy of mtcars > # Change cyl from numeric to factor > mtcars1$cyl <- factor(mtcars1$cyl) > > ggplot(mtcars1, aes(x = cyl, y = mpg, fill = cyl, > colour = cyl)) + > 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") + > scale_colour_manual(values = c("orange", "brown", "forestgreen")) + > scale_fill_manual(values = c("orange", "brown", "forestgreen")) > > Dennis > > On Mon, Mar 31, 2014 at 7:43 PM, Monica Pisica <pisican...@hotmail.com> wrote: > > Hi, > > > > > > > > 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") > > > > > > p1 > > > > > > > > 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, > > > > > > Monica > > ______________________________________________ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.