使用showtext包处理信息
在系统字体存储盘中找到想要的字体,右键-属性找到其真正的名字。例如:楷书的名字为“simkai.ttf”
使用font_add函数添加字体
font_add(myfont, "simkai.ttf") ##添加字体
font.families() ##查看添加的字体
[1] "sans" "serif" "mono" "wqy-microhei" "myfont"
使用showtext包中的函数加载和去掉字体
showtext.begin()##加载字体
showtext.end()##去掉字体
使用Cairo包导出:我们在用作图的时候会发现,如果含有中文的话,通过showtext设置了语言。在保存为png或者jpeg格式的时候是发现字体改变了。但是如果在保存为pdf格式的时候会发现中文全是...或者会发生错误。这个时候就需要用到Cairo包中了。
Cairo.capabilities() ##查看cairo包支持的所有导出格式
png jpeg tiff pdf svg ps x11 win raster
TRUE FALSE FALSE TRUE TRUE TRUE FALSE TRUE TRUE
可以运行下面代码试试
library("ggplot2")
library("Cairo")##加载所需要的包
font_add("myfont","simkai.ttf") ##加载字体
font.families() 显示字体
[1] "sans" "serif" "mono" "wqy-microhei" "myfont" "wmpeople1"
CairoPDF("mm.pdf")
showtext_begin() ##使用字体
ggplot(diamonds,aes(color,fill=cut))+
geom_bar()+
ggtitle("钻石质量情况")+
theme(title=element_text(family="myFont"))
showtext_end() ##停止使用字体
dev.off()








暂无数据