install.packages("showtext")
library(showtext)
y2<-font_files()
View(y2)
#查看从系统导入的字体以及字体的路径 /System/Library/Fonts/Supplemental .ttf .ttc
showtext_auto(enable = TRUE)
#在全局环境使用相应的字体 相关的代码有showtext_begin() showtext_end()
font_add("Songti","/System/Library/Fonts/Songti.ttc")
font_add("Times","/System/Library/Fonts/Supplemental/Times New Roman.ttf")
#前面是在R语言系统中的名字,后面是路径
font_families()
#[1] "sans"
#[2] "serif" 这个和Times New Roman一样
#[3] "mono"
#[4] "wqy-microhei"
#[5] "Times" 这就是新加入的Times New Roman
#[6] "Arial"
#[7] "Songti" 宋体
#字体实验1
install.packages("ggplot2")
library(ggplot2)
a3<-ggplot(mtcars,aes(cyl))+
geom_bar()+
xlab(label = '我是谁') +
ylab(label = '我从哪里来') +
labs(title="where")+
theme_bw(base_family = "Songti")
#字体实验2