Change ggplot2 default


Obviously, ggplot2 has a way to set plot symbol, colors, line type, etc. to some default when users use geom_* calls without argument. How can one change these default globally instead of setting geom_arguments to given values?

I am specifically interested in the cases where data is not stratified, ie no aesthetics is used to group the data by strata.

The problme can be illustrated by replacing the typical sequence:

gdata <- data.frame(x = 1:10, y = 1:10)
ggplot(data = gdata) +
  aes(x = x, y = y) +
  geom_point(colour = 'red', shape = 21) 

by the use of some custom function change_ggplot2_default() which would do the same thing

#ggplot(data = gdata) +
#  aes(x = x, y = y) +
#  change_ggplot2_default()

Thank you in advance


PS: I thought about using scale_*_manual but that does not work if the aesthetics are not used.

I don't have a lot of experience but wonder if you could do what you want with Themes?


You can do this with the update_geom_defaults function. For example:


ggplot(mtcars, aes(mpg, hp)) +

update_geom_defaults("point", list(shape=21, colour="red"))

ggplot(mtcars, aes(mpg, hp)) +

Created on 2021-05-09 by the reprex package (v1.0.0)

1 Like

Thank you. That will do perfectly

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.