如何在ggplot中仅旋转注释中的文本?

时间:2021-01-27 14:58:49

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")

如何在ggplot中仅旋转注释中的文本?

How would I rotate just the annotated text 90 degrees so that it is parallel to the reference line?

如何将带注释的文本旋转90度,使其与参考线平行?

1 个解决方案

#1


41  

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).

在?geom_text中,您可以看到角度是一种可能的美学,注释将传递它,就像geom_text理解的任何其他参数(例如已经使用的x,y,标签和颜色)一样。

#1


41  

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).

在?geom_text中,您可以看到角度是一种可能的美学,注释将传递它,就像geom_text理解的任何其他参数(例如已经使用的x,y,标签和颜色)一样。