2013-12-10 54 views
6

私のMacでggplot2を使ってプロットを作成しました。フォントをTimes New Romanに変更しました。これは問題なく動作します。WindowsとMacでggplot2のフォントを変更

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)))) 

これは、Mac上の結果である:私は私がのTimes New Romanにフォントを変更することはできませんWindows上でRメーカー、使用してWMF形式でプロットをエクスポートする必要が http://i.imgur.com/wRmvPZq.jpg

。私は成功していない上記のコードに加えて、次のことをしました。

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の場合よりもグラフの線が滑らかに見えるのはなぜですか?

誰か助けてもらえますか?ありがとうございました!

+0

関連:https://stackoverflow.com/questions/34522732/changing-fonts-in-ggplot2 –

答えて

2

loadfonts()ではなくプロットを描画する前にloadfonts(device="win")を使用すると、私のために働いた。私は後者(または全く呼び出しがない)がOS Xで十分である理由がわからない。私は、何らかの種類のデフォルトデバイスがあると仮定することができます。

関連する問題