2014-12-21 19 views
14

Ho un terreno come questo:Come ruotare solo il testo nelle annotazioni in ggplot?

fake = data.frame(x=rnorm(100), y=rnorm(100)) 

ggplot(data=fake, aes(x=x, y=y)) + geom_point() + theme_bw() + 
    geom_vline(xintercept=-1, linetype=2, color="red") + 
    annotate("text", x=-1, y=-1, label="Helpful annotation", color="red") 

enter image description here

Come dovrei ruotare solo le annotazioni di testo di 90 gradi in modo che sia parallela alla linea di riferimento?

risposta

33

Basta dire l'angolo desiderato.

ggplot(data = fake, aes(x = x, y = y)) + 
    geom_point() + 
    theme_bw() + 
    geom_vline(xintercept = -1, linetype = 2, color = "red") + 
    annotate(geom = "text", x = -1, y = -1, label = "Helpful annotation", color = "red", 
      angle = 90) 

In ?geom_text si può vedere che angle è una possibile estetica, e annotate passerà sul lungo come tutto il resto.

Problemi correlati