2017-09-04 59 views
0

我可以將基本geom_ *圖層與來自第三方庫的「stat」屬性結合起來嗎?和基本ggplot stat_ *圖層與其他庫geoms。ggplot2與擴展庫結合使用

我有簡單的例子:

require(ggrepel)  
Plot1<- ggplot(data=mpg, aes(x=cty, y=hwy)) + 
    geom_point()+ 
    stat_sum(aes(label=..n..), alpha=.5, colour=c("red"), size=3, geom="text") 

在這個例子中,我想從ggrepel包替換第三方「geom_text_repel」「文本」 GEOM。在這種情況下我更改屬性GEOM =「文本」,以GEOM =「text_repel」,會出現一個錯誤信息:出現在我想使用GGPLOT2 geom_ *層第三方統計的情況下

Error: Found object is not a geom.

類似的錯誤。

如何解決此錯誤?

回答

1

此代碼的工作對我R 3.4.1ggplot2_2.2.1.9000ggrepel_0.6.5):

library(ggplot2) 
library(ggrepel)  
Plot1 <- ggplot(data=mpg, aes(x=cty, y=hwy)) + 
    geom_point() + 
    stat_sum(aes(label=..n..), alpha=.5, colour=c("red"), size=3, geom="text_repel") 
Plot1 

enter image description here