What I want to do
I currently have a custom theme for my plots, and I want to have on top of that some predefined parameters for all type of plots. My first focus is on bar charts, where I want to change the default width.
The default width of geom_bar in ggplot2 is "By default, set to 90% of the resolution of the data." (http://ggplot2.tidyverse.org/reference/geom_bar.html).
I'd like to change that default to 75%. To be clear, I am not interested in changing it like this:
geom_bar(stat='identity', width=0.75)
Because that would mean I have to specify it everytime I create a bar chart. I want it to be the new default.
What I tried so far
I tried to change the width default using this:
update_geom_defaults("bar", list(width=0.75))
But then I get an error message: Error: Aesthetics must be either length 1 or the same as the data (964): width
. I'm thinking this might be due to the fact that the width is calculated based on the resolution of the data, which is not yet there at the moment I call update_geom_defaults
Plus, I also realised that width
is not part of the default aes of the bars :
GeomBar$default_aes
* colour -> NA
* fill -> "grey35"
* size -> 0.5
* linetype -> 1
* alpha -> NA
My questions are:
- Where is that 90% default set?
- Can I change it in any way?
- If not, is there another way to pass a predefined set of parameters to all the geom_* functions?
Thanks !