在R语言中设置字体时需要利用**windowsFonts()**加入到字体库中,例如:
windowsFonts(myFont = windowsFont("微软雅黑"))
然后在调用时,用family='myFont’的参数实现即可。
my_theme <- theme( panel.background = element_rect(fill = "transparent", colour = NA), plot.background = element_rect(fill = "transparent", colour = NA), legend.background = element_rect(fill = "transparent", colour = NA), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), title=element_text(family="myFont"), legend.text=element_text(size=14,family = 'myFont'), axis.title=element_text(size=14,family = 'myFont'), axis.text = element_text(size=14,family = 'myFont'), strip.text.x=element_text(size=14, family='myFont') )
plot(1:10,1:10,xlab='好好学习',ylab='你好',cex.lab=2,family='myFont')