加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 04:14:30 所属栏目:Windows 来源:网络整理
导读:我在我的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="
我在我的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,position="identity")+
  stat_density(aes(x=R3,colour="rho = 0"),linetype=2,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,axis.title.y=element_text(vjust=-0.25,legend.text=element_text(size=14,legend.title=element_blank(),legend.margin=unit(1,"cm"),legend.key.height=unit(1,"line"),legend.key.size=unit(0.8,legend.key=element_rect(fill=NA),legend.background=element_blank(),plot.margin=unit(c(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上的结果:
http://i.imgur.com/wRmvPZq.jpg

我需要以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上的结果:
http://i.imgur.com/gMVAxDx.jpg

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

有人可以帮忙吗?谢谢!

在渲染绘图之前使用loadfonts(device =“win”)而不仅仅是loadfonts(),对我有用.我不确定为什么后者(或根本没有调用)足以在OS X上运行;我只能假设某种默认设备正在发生.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读