Change the font of all ggplot-outputs once in code instead of with every plot? [duplicate]

与世无争的帅哥 提交于 2021-02-11 13:53:18

问题


Working with a quite huge R Markdown document, I was wondering whether it is possible to define the the font of my ggplots once in some kind of global setting? Just like I can use theme_set() to define theme_minimal() for all the plots in the document.

I tried adding something like this, but it threw an error:

theme_set(text = element_text(size=12, family="Times New Roman"))

Is this possible or would I have to define the font for each of my outputs individually?


回答1:


Wrap your custom settings in theme():

theme_set(theme(text = element_text(size=12, family="Times New Roman")))



回答2:


To answer @SnupSnurre, yes. To tweak an existing theme you can say. for example:

theme_set(theme_minimal() + theme(text = element_text(size=12, family="Times New Roman")))

to make global changes or

ggplot() + ...
  theme_minimal() +
  theme(text = element_text(size=12, family="Times New Roman")

to modify an individual plot



来源:https://stackoverflow.com/questions/61949945/change-the-font-of-all-ggplot-outputs-once-in-code-instead-of-with-every-plot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!