问题
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