如何更改 ggplot2中的默认字体大小

我想知道是否有可能改变一些 ggplot2图形的默认参数,例如字体大小,为整个 R 会话。这个想法是为了避免为每个情节设置它们。

80032 次浏览

Use theme_set()

theme_set(theme_gray(base_size = 18))
qplot(1:10, 1:10)

enter image description here

Use theme_set if you want to update for the remainder of your active session:

theme_set(theme_grey(base_size = 18))

If you only want to change one graph you can set the base_size in the theme:

qplot(1:10, 1:10) + theme_grey(base_size = 18)
ggplot(mtcars, aes(x = mpg, y = cyl)) +
geom_point() +
theme_grey(base_size = 18)