我使用ggplot
包在R中绘制了一个图,同时使用以下代码更改了文本的字体。
require(ggplot2)
require(extrafont)
x1 <- runif (100,0,1)
x2 <- x1 + runif (100,0,1)
d <- data.frame(x1=x1, x2=x2)
ggplot(d, aes(x1, x2))+geom_point()+
geom_smooth()+
ggtitle("") +
xlab("A") + ylab("Proportion") +
theme_bw() +
theme(text=element_text(family="Times New Roman", face="bold", size=12))
我使用RStudio以PDF格式导出图形。然后,将图形导入到Word文档中。但是,当我使用Microsoft Word打开文档时,文本没有显示在图形中。当我不将字体更改为Times New Roman时,不会发生这种情况。
如果能听到任何建议,我将不胜感激。谢谢。
答案 0 :(得分:1)
感谢许多有用的评论,尤其是Jon Spring提供的链接,我得以解决我的问题。我想在这里写下由于类似问题而到达这里的人的代码。
我采用的方法是使用extrafont
包的embedFonts
函数将字体嵌入到PDF中。
require(ggplot2)
require(extrafont)
x1 <- runif (100,0,1)
x2 <- x1 + runif (100,0,1)
d <- data.frame(x1=x1, x2=x2)
pdf("a.pdf")
ggplot(d, aes(x1, x2))+geom_point()+
geom_smooth()+
ggtitle("") +
xlab("A") + ylab("Proportion") +
theme_bw() +
theme(text=element_text(family="Times New Roman", face="bold", size=12))
dev.off()
embedFonts(file = "a.pdf")