R 图中的字体大小和字体样式(带有 R 基础绘图)

问题描述 投票:0回答:1

我正在努力寻找一种方法来更改 R 中图形的字体样式和字体大小。我想要 Arial 12 中图形中的所有文本。我经常使用 cex 命令来增加和减少字体,但现在我想要专门 12 字体大小。我没有使用任何专门的绘图包,只是使用 R 基本绘图函数,如plot()。

我尝试安装和使用包 extrafont,遵循这篇文章:Changing Fonts for Graphs in R 但它给了我以下错误。我不明白为什么它说“找不到功能“主题”。我确实安装并加载了该软件包,并按照帖子中给出的说明进行操作。

> plot(hfit) +
+ theme(text=element_text(family="Times New Roman", face="bold", 
size=12))
Error in theme(text = element_text(family = "Times New Roman", face 
= "bold",  : 
could not find function "theme"

来自这篇文章:在 R 数字中指定字体大小我想我可以使用 par(ps=12) 来表示字体大小 12,但我不知道如何准确使用这个函数。我尝试了这个“plot(hfit, par(ps=12))”,但我认为这段代码是错误的。 如果有人可以请告诉我任何简单的方法来获取 Arial 12 中的所有图形字体。

谢谢你

r plot font-size font-style
1个回答
0
投票

您可以直接在

font
中指定
family
plot
theme()
是一个ggplot2函数。

> par(mfrow=c(2, 2))
> plot(1:10)
> plot(1:10, font=2)
> plot(1:10, family='Roman')
> plot(1:10, font=2, family='Roman')

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.