在我的研究中,我使用R生成了各种各样的图形.我发现大多数图形都有不同大小的无衬线字体.
如何将图形中的所有文本(x标签、y标签、标题、图例等)更改为统一字体,例如Times New Roman、12pt、Bold?
在我的研究中,我使用R生成了各种各样的图形.我发现大多数图形都有不同大小的无衬线字体.
如何将图形中的所有文本(x标签、y标签、标题、图例等)更改为统一字体,例如Times New Roman、12pt、Bold?
你可以用extrafont美元.
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和here.再看看github project page.