使用注释添加不同的注释不同方面(Using annotate to add different an

2019-06-25 11:43发布

我试图面板标签的剧情添加到不同的方面。 我想他们是1:7,但是,下面的代码

d <- ggplot(diamonds, aes(carat, price, fill = ..density..)) +
     xlim(0, 2) + stat_binhex(na.rm = TRUE) + opts(aspect.ratio = 1)

d1<-d + facet_wrap(~ color)

d1+annotate("text", x=0.25, y=1.5e+04, label=1:7)

产量

Error: When _setting_ aesthetics, they may only take one value. Problems: label

现在,我可以提供一个单一的价值和获取在所有方面复制。 但是,我怎么能已经在不同方面不同的标签使用注释()?

Answer 1:

借助annotate ,你不能。 但是,通过设置data.frame并将其作为一个数据源geom_text ,很容易(少数簿记方面)。

d1 + geom_text(data=data.frame(x=0.25, y=1.5e+04, label=1:7, 
                               color=c("D","E","F","G","H","I","J")), 
               aes(x,y,label=label), inherit.aes=FALSE)



文章来源: Using annotate to add different annotations to different facets
标签: r ggplot2