19

我正在尝试将面板标签添加到图中的不同方面。我希望它们是 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

现在,我可以提供一个值并将其复制到所有方面。但是如何使用 annotate() 在不同的方面拥有不同的标签?

4

1 回答 1

26

annotate你不能。但是通过设置 adata.frame并将其用作 a 的数据源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)

在此处输入图像描述

于 2012-06-13T21:05:21.020 回答