0

I would like to change the default colors and fills for all of the geoms in ggplot2. I came across this post and this post which helped me get started on changing the defaults.

However, when I try to change the default for histograms using update_geom_defaults or update_stat_defaults I get the error:

Error: Can't find geom called "histogram"

Is there a way to update colors and fills for geom_histogram using update_*_defaults?

Code:

library(tidyverse)
update_geom_defaults("histogram", list(fill = "black", colour = "black"))

update_stat_defaults("histogram", list(fill = "black", colour = "black"))
#works in ggplot call
ggplot(mtcars)+
    geom_histogram(aes(x=mpg), bins = 5, fill = "black")
#works for other geom_*
update_geom_defaults("point", list(fill = "green", colour = "green"))

ggplot(mtcars)+
  geom_point(aes(x=mpg,y=cyl))

#additional arguments that do not work with either update function
neither <- c("freqpoly", "histogram",   "jitter","sf_label","sf_text")

Using version R 3.6 and 3.2.0 for ggplot2

Mike
  • 3,797
  • 1
  • 11
  • 30
  • 1
    see comment: https://github.com/tidyverse/ggplot2/issues/2456 – Ben Jul 02 '19 at 16:24
  • @Ben thanks for the heads up, do you know anyway around that? possibly writing over the `geom_histogram` function with specifying fill and color args? – Mike Jul 02 '19 at 18:59
  • take a look at this as well: https://emanuelaf.github.io/own-ggplot-theme.html - what is your overall goal with ggplot? – Ben Jul 02 '19 at 19:53
  • @Ben my overall goal is to set a theme and color palette for my company, I am able to get the themes but having trouble setting the colors for each `geom` specifically if I try to set more than one color in the the `update_geom_defaults` I get inconsistent behavior. I realize that I am getting on the border of asking a totally different question here. – Mike Jul 11 '19 at 20:17
  • i wish i had more to offer. did you try what the other person described in github issue: update_geom_defaults("bar", list(fill = "tomato")) for histogram? i suppose you could redefine the ggplot functions (perhaps might lead to other problems), wish i could help more – Ben Jul 12 '19 at 01:29
  • @Ben yea that does work, but I might try to redefine the functions and see what happens. Thanks for your help! – Mike Jul 12 '19 at 17:12

0 Answers0