在Windows vs Mac上更改ggplot2中的字体

 asd54w464wq_212 发布于 2023-02-11 18:08

我在我的mac上使用ggplot2创建了一个绘图.我将字体更改为Times New Roman,效果很好.

library(extrafont)

ggplot(data=df)+
  stat_density(aes(x=R1, colour="rho = -0,6"), 
               adjust=4, lwd=0.65, geom="line", position="identity")+
  stat_density(aes(x=R2, colour="rho = 0,6"), 
               adjust=4, lwd=0.65, geom="line", position="identity")+
  stat_density(aes(x=R3, colour="rho = 0"), 
               adjust=4, lwd=0.65, linetype=2, geom="line", position="identity")+
  xlim(-1, 1)+
  xlab("Renditen")+
  ylab("Dichte")+
  ggtitle("Renditeverteilung im Heston-Modell")+
  theme(plot.title=element_text(face="bold", size=16, vjust=2, family="Times New Roman"),  
        axis.title.x=element_text(vjust=-1, size=14, family="Times New Roman"),
        axis.title.y=element_text(vjust=-0.25, size=14, family="Times New Roman"), 
        legend.text=element_text(size=14, family="Times New Roman"), legend.title=element_blank(),
        legend.margin=unit(1, "cm"),
        legend.key.line"), 
        legend.key.size=unit(0.8, "cm"), 
        legend.key=element_rect(fill=NA), 
        legend.background=element_blank(),
        plot.margin=unit(c(1,1,1,1), "cm"))+
  scale_colour_manual(values=c("red","black", "blue"), labels=greeks_rho)+
  guides(colour=guide_legend(override.aes=list(linetype=c(1,3,1))))

这是Mac上的结果:

在此输入图像描述

我需要以WMF格式导出绘图,所以我在Windows上使用R Studio,我无法将字体更改为Times New Roman.除了上面的代码之外我还做了以下代码而没有成功.

library(extrafont)
font_import()
loadfonts()

我得到这样的警告(英文:〜"在Windows字体数据库中找不到字体系列")

47: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  Zeichensatzfamilie in der Windows Zeichensatzdatenbank nicht gefunden

这是Windows上的结果:

在此输入图像描述

并且:为什么Mac上的图形线看起来比在Windows上要平滑得多?

有人可以帮忙吗?谢谢!

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有