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:
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:
And: Why do the lines of the graphs look a lot smoother on Mac than on Windows?
Can somebody help here? Thank You!
ggplot allows you to change the font of each part of the figure: you just need to know the correct option to modify in the theme. (For a full list of customizable components of the theme, see this documentation.)
The Macintosh components (which includes the . AFM file) and the Windows components (. PFB and . PFM files) are all included in an OpenType font file, which means you can install and use the same font file on both Windows and Macintosh computers.
Mac OS X tries to render fonts exactly as they were designed, whereas Windows tries to alter them slightly to make them more readable.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With