Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot2: How do I set the default fill-colour of geom_bar() in a theme [duplicate]

Tags:

r

ggplot2

I'd like to define a theme for ggplot2 so that the default colour of geom_bar() is not black.

How can I do this?

like image 895
JerryWho Avatar asked Jun 17 '13 14:06

JerryWho


2 Answers

you can't do it in a theme (sadly).

You want to change the default settings of a geom,

  update_geom_defaults("bar",   list(fill = "red"))

and you can also change a default scale, e.g.

  scale_colour_continuous <- function(...) 
         scale_colour_gradient(low = "blue", high = "red", na.value="grey50", ...)
like image 195
baptiste Avatar answered Oct 22 '22 07:10

baptiste


Theme controls apperance of non-data elements, so you need to work with scale functions. Try scale_fill_brewer, e.g.:

 scale_fill_brewer(palette = "Set1")

For details on this function see here.

like image 33
topchef Avatar answered Oct 22 '22 05:10

topchef