在我的研究中,我使用 R 生成各种图表。我发现大多数图表都带有各种大小的 Sans Serif 字体。
如何将图表中的所有文本(x 标签、y 标签、标题、图例等)更改为统一字体,例如Times New Roman,12pt,粗体?
您可以使用外字体包裹。
install.packages("extrafont")
library(extrafont)
font_import()
loadfonts(device="win") #Register fonts for Windows bitmap output
fonts() #vector of font family names
## [1] "Andale Mono" "AppleMyungjo"
## [3] "Arial Black" "Arial"
## [5] "Arial Narrow" "Arial Rounded MT Bold"
library(ggplot2)
data(mtcars)
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +
ggtitle("Fuel Efficiency of 32 Cars") +
xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
theme_bw() +
theme(text=element_text(family="Times New Roman", face="bold", size=12)) #Times New Roman, 12pt, Bold
#example taken from the Github project page
Note:使用extrafont
包中,您还可以将这些字体嵌入 PDF 和 EPS 文件中(在 R 中绘图并导出到 PDF/EPS)。您还可以直接创建数学符号(请参见下图中的数学方程),通常使用 TeX 创建。更多信息here and here。另请参阅github项目页面.
还看this描述创建的答案xkcd使用样式图extrafont
包裹。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)