在Windows和Mac上更改ggplot2中的字体 [英] Change font in ggplot2 on Windows vs Mac
问题描述
我在我的Mac上使用ggplot2创建了一个图。我将字体更改为Times New Roman,这很好。
library(extrafont)
ggplot (data = df)+
stat_density(aes(x = R1,color =rho = -0,6),
adjust = 4,lwd = 0.65,geom =line,position = 身份)+
stat_density(aes(x = R2,color =rho = 0,6),
adjust = 4,lwd = 0.65,geom =line,position =identity )+
stat_density(aes(x = R3,color =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.ti tle = element_blank(),
legend.margin =单位(1,cm),
legend.key.height =单位(1,line),
legend.key。 size = unit(0.8,cm),
legend.key = element_rect(fill = NA),
legend.background = element_blank(),
plot.margin = unit(c (color = 1,1,1,1),cm))+
scale_colour_manual(values = c(red,black,blue),labels = greeks_rho)+
guides = 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()
我收到这样的警告(英文:〜Font Family not found in Windows字体数据库)
47:在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()
,为我工作。我不确定为什么后者(或者根本不打电话)是足够的nt在OS X上;我只能假设有某种默认设备正在进行。 I created a plot using ggplot2 on my mac. I changed the fonts to Times New Roman, which works fine.
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.height=unit(1, "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))))
This is the result on Mac: http://i.imgur.com/wRmvPZq.jpg
I need to export the plot in the WMF format so I used R Studio on Windows, where I cannot change the font to Times New Roman. I did the following in addition to the above code without success.
library(extrafont)
font_import()
loadfonts()
I get warnings like this (in English: ~ "Font Family not found in Windows Font Database")
47: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), ... :
Zeichensatzfamilie in der Windows Zeichensatzdatenbank nicht gefunden
This is the result on Windows: http://i.imgur.com/gMVAxDx.jpg
And: Why do the lines of the graphs look a lot smoother on Mac than on Windows?
Can somebody help here? Thank You!
Using loadfonts(device="win")
before rendering the plot, rather than just loadfonts()
, worked for me. I'm not sure why the latter (or no call at all) is sufficient on OS X; I can only assume there's some sort of default device thing going on.
这篇关于在Windows和Mac上更改ggplot2中的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!