2013-12-10 21 views
6

Tôi đã tạo một ô sử dụng ggplot2 trên mac của mình. Tôi đã thay đổi phông chữ thành Times New Roman, hoạt động tốt.Thay đổi phông chữ trong ggplot2 trên Windows và Mac

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

Đây là kết quả trên Mac: http://i.imgur.com/wRmvPZq.jpg

tôi cần phải xuất khẩu những âm mưu trong các định dạng WMF vì vậy tôi sử dụng R Studio trên Windows, nơi tôi không thể thay đổi phông chữ Times New Roman. Tôi đã làm như sau ngoài các mã trên mà không thành công.

library(extrafont) 
font_import() 
loadfonts() 

tôi nhận được cảnh báo như thế này (bằng tiếng Anh: ~ "không tìm thấy Font Family trong cơ sở dữ liệu Windows Font")

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

Đây là kết quả trên Windows: http://i.imgur.com/gMVAxDx.jpg

Và: Tại sao các dòng đồ thị trông mượt mà hơn trên Mac so với Windows?

Ai đó có thể trợ giúp ở đây? Cảm ơn bạn!

+0

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

Trả lời

2

Sử dụng loadfonts(device="win") trước khi hiển thị ô, thay vì chỉ loadfonts(), đã hoạt động đối với tôi. Tôi không chắc chắn lý do tại sao sau này (hoặc không có cuộc gọi nào cả) là đủ trên OS X; Tôi chỉ có thể giả định có một số loại thiết bị mặc định đang diễn ra.

Các vấn đề liên quan