2012-06-13 13 views
15

Próbuję dodać etykiety paneli do różnych aspektów w wątku. Chcę, żeby być 1: 7, ale następujący kodUżywanie adnotate do dodawania różnych adnotacji do różnych aspektów

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) 

daje

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

Teraz mogę podać jedną wartość i dostać że powielane we wszystkich aspektach. Ale w jaki sposób mogę mieć różne etykiety w różnych aspektach za pomocą adnotate()?

Odpowiedz

21

Z annotate, nie można. Ale ustawienie data.frame i użycie go jako źródła danych dla geom_text jest łatwe (z kilkoma aspektami księgowymi).

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) 

enter image description here

Powiązane problemy