[R] ggplot2: changing default colors of boxplot

Dennis Murphy djmuser at gmail.com
Wed Oct 5 01:41:58 CEST 2011


Hi:

Try this:

p <- ggplot(mtcars, aes(factor(cyl), mpg))
p + geom_boxplot(aes(colour = factor(am)), fill = 'white') +
     scale_colour_manual('am', values = c('0' = 'blue', '1' = 'black'))

HTH,
Dennis

On Tue, Oct 4, 2011 at 1:56 PM, Brian Smith <bsmith030465 at gmail.com> wrote:
> Hi,
>
> I wanted to change the default colors appearing in boxplot. For example, the
> following code (from the package/documentation):
>
> ===========
> library(ggplot2)
>
> p <- ggplot(mtcars, aes(factor(cyl), mpg))
> p + geom_boxplot(aes(fill = factor(am)))
>
> ===========
>
> Gives the default colors. What do I need to do to modify this so that:
>
> 1. Change the colors from green and red to blue and black
> 2. Only have the outline of the boxplot colored (and not fill in the box)
>
>
> thanks,
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list