2017-09-04 61 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