旋转轴标题

时间:2019-11-20 21:08:28

标签: r ggplot2

p <- ggplot(mtcars, aes(cyl, mpg)) +
  geom_point()

# Create a simple secondary axis
p + scale_y_continuous("m1", sec.axis = sec_axis(~ . + 10, name = ("m2")))

如您所见,“ m1”和“ m2”正朝向该图,我想知道如何将“ m2”旋转90度?因此,它面对的方向与“ m1”相同?我尝试使用“旋转”,但在sec.axis中不允许。

1 个答案:

答案 0 :(得分:2)

尝试

ggplot(mtcars, aes(cyl, mpg)) +
  geom_point() + 
  scale_y_continuous("m1", sec.axis = sec_axis(~ . + 10, name = ("m2"))) +
  theme(axis.title.y.right = element_text(angle=90))