2017-10-10 92 views
-1

[字體問題已解決,但現在問題在於字母不在SBT欄上。它給了我兩倍的SBT,在圖中突出顯示]ggplot R,網格調用和字體族中的錯誤

我正在使用ggplot作爲一個barplot,並得到這個錯誤。

In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : 
    font family not found in Windows font database​ 

我試圖安裝extrafont但仍然出現此錯誤。 即時通訊使用R.version 3.4.2 以下是我的代碼:

library(ggplot2) 
    plot2 <- ggplot(Test, aes(x=factor(Test$habitat3), y=proportion, fill=proportion)) + 
geom_bar(stat="identity", position="stack", colour="black", fill="grey") + 
geom_errorbar(aes(ymin=stdlow, ymax=stlup, width=0, position="identity")) + 
xlab("Habitat") + 
ylab("root abundance") + 
coord_cartesian(ylim = c(0, 1)) + 
scale_y_continuous(expand=c(0,0)) + 
theme(axis.title.x=element_text(margin = unit(c(6, 0, 0, 0), "mm"))) + 
theme(axis.title.y=element_text(margin = unit(c(0, 6, 0, 0), "mm"))) + 
theme(axis.line.x = element_line(color="black"), axis.line.y = element_line(color="black")) + 
theme(text = element_text(size=14, colour = "black")) + 
theme(legend.position="none") + 
theme(axis.text.y = element_text(size = 14, colour = "black")) + 
theme(axis.text.x = element_text(size = 14, colour = "black")) + 
theme(plot.background=element_blank(), 
panel.grid.major=element_blank(), 
panel.background=element_blank(), 
panel.grid.minor=element_blank(), 
legend.key=element_blank(), 
legend.background=element_blank()) + 
theme(text=element_text(family = "Arial")) + 
annotate("text", x="PV", y=3.1, label="ab") + 
annotate("text", x="WB", y=4.18, label="a") + 
annotate("text", x="AF", y=2.98, label="b") + 
annotate("text", x="EZ", y=3.43, label="ab") 
+0

什麼是確切的錯誤? – sissy

+1

請提供一個可重現的例子 –

+0

使用dput(YOUR_DATA) –

回答

1

你可以嘗試先用extrafont註冊字體。

library(extrafont) 

font_import() 

loadfonts(device = "postscript") 

然後你就可以在GGPLOT2使用它:

library(ggplot2) 

p <- ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) 

p + geom_text(family = "Arial") 

這將產生:

enter image description here