How to rotate only text in annotation in ggplot?
I have a plot like this:
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")
How would I rotate just the annotated text 90 degrees so that it is parallel to the reference line?
Just tell it the angle you want.
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
you can see that angle
is a possible aesthetic, and annotate
will pass it along, just like any other argument geom_text
understands (such as the x
, y
, label
, and color
already being used).