Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ggplot2 centre y axis title

Tags:

r

ggplot2

I'm sure there's a simple solution but I have looked around and can't find anything.

Essentially I just want to flip the y-axis title horizontally then center it along the y-axis. I have managed to flip it but I can't seem to find an argument that centers it along the axis.

Here is a reproducible example:

require(tidyverse)

iris %>% ggplot() + geom_point(aes(x = Sepal.Length, y = Sepal.Width)) +
theme(axis.title.y = element_text(angle=0))

Thanks ahead!

like image 841
Dasr Avatar asked Jun 27 '26 12:06

Dasr


1 Answers

If I understood you correctly, you were almost there. Under the argument element_text, you can edit the arguments vjust and hjust for vertical and horizontal positioning.

require(tidyverse)

iris %>% ggplot() + geom_point(aes(x = Sepal.Length, y = Sepal.Width)) +
theme(axis.title.y = element_text(angle=0, vjust = 0.5))

enter image description here

like image 136
DJV Avatar answered Jun 29 '26 14:06

DJV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!