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

As you can see "m1" and "m2" is facing towards the figure I am wondering how can I rotate "m2" 90-degrees? So it faces in the same orientation as "m1"? I tried using "rotate" but it's not allowed in sec.axis.

tjebo
  • 12,885
  • 4
  • 34
  • 61
bvowe
  • 2,252
  • 10
  • 18
  • see https://stackoverflow.com/questions/1330989/rotating-and-spacing-axis-labels-in-ggplot2 ? you just needa do axis.text.y.. – StupidWolf Nov 20 '19 at 21:13

1 Answers1

2

Try this

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