[R] ColorBrewer question

R. Michael Weylandt michael.weylandt at gmail.com
Mon Jan 30 05:22:50 CET 2012


I believe you need to use the scale_fill_brewer since fill is the
color of the bars while color is the outside of the bars in
ggplot2-speak:

E.g., with built-in data (it's polite to provide yours so that your
minimal working example is working):

data(diamonds)
ggplot(diamonds, aes(clarity)) + geom_bar(aes(fill = clarity, color = clarity))

# Note the borders are now changed but the fill is the same
ggplot(diamonds, aes(clarity)) + geom_bar(aes(fill = clarity, color =
clarity)) + scale_color_brewer(pal = "Blues")

# Now the fill is changed, but you probably want to drop the border
coloring since it's hideous against the blues
ggplot(diamonds, aes(clarity)) + geom_bar(aes(fill = clarity, color =
clarity)) + scale_fill_brewer(pal = "Blues")

# So lovely
ggplot(diamonds, aes(clarity)) + geom_bar(aes(fill = clarity)) +
scale_fill_brewer(pal = "Blues")

Michael

On Sun, Jan 29, 2012 at 12:21 PM, Mario Giesel <rr.giesel at yahoo.de> wrote:
> Hello, R friends,
>
> I'm trying to change colors of my horizontal bars so that they show a sequence.
> I chose the ColorBrewer palette "Blues". However the resulting plot doesn't show any changes to the default.
> I tried several places of "+ scale_colour_brewer(type="seq", pal = "Blues")" with no effect.
> This is my code:
>
> p <- ggplot(data, aes(x = gender))  + scale_y_continuous("",formatter="percent") + xlab("Gender") + coord_flip() +     scale_colour_brewer(type="seq", pal = "Blues")
> p+geom_bar(aes(fill=pet),colour='black',position='fill')
>
>
> Any ideas welcome.
> Thanks,
>  Mario
>        [[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