ggplotグラフに2つの注釈を追加します。 グラフにp1
のようなfacet_grid
が含まれていない場合、このようなannotate
層を追加すると、つまりq1
が正常に機能します。しかし、私は、同じ「注釈」層、エラー報告で、すなわち、q2
結果追加、元のグラフ、即ち、p2
に、facet_grid
層を追加する場合:`ggplot2`の` annotate`は、 `facet_grid`と組み合わせてエラーを報告します。
Error: Aesthetics must be either length 1 or the same as the data (4): label
任意の提案?ありがとう。
PSでは、私が使用したggplot2パッケージのバージョンは2.2.1です。
p1 <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() p2 <- p1 + facet_grid(vs~.) q1 <- p1 + annotate("text", x = 2:3, y = 20:21, label = c("my label", "label 2")) q2 <- p2 + annotate("text", x = 2:3, y = 20:21, label = c("my label", "label 2"))