Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Axis title won't rotate when y-axis is on the right

I am trying to generate a plot with y-axis on the right and I would like to rotate the y-axis title to be horizontal. Here’s some sample code :

ggplot() + geom_function(fun = ~ -.x) + 
      scale_x_continuous(limits = c(-0.27,0),name = "example")+
      scale_y_continuous(position = "right",limits = c(0,0.27),name = "test")+
      theme_classic()+
      theme(axis.title.y = element_text(angle = 0, hjust = 0), 
            axis.title.x = element_text(hjust = 0))

"angle = 0" doesn’t seem to do anything when you set "position = "right"", but works fine when you use the default y-axis position. Why this is happening and how do I rotate the title when y-axis is on the right?

Thank you.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have to use the theme element axis.title.y.right

ggplot() + geom_function(fun = ~ -.x) + 
  scale_x_continuous(limits = c(-0.27,0),name = "example")+
  scale_y_continuous(position = "right",limits = c(0,0.27),name = "test")+
  theme_classic()+
  theme(axis.title.y.right = element_text(angle = 0), 
        axis.title.x = element_text(hjust = 0))

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading