Position of axis names in ggplot, relative placement?

Does anyone have an idea about placing axis names in ggplot?

ggplot(mtcars, aes(x=mpg, y=hp)) + geom_point() + ylab("HP") + ylim(50,350) + xlim(10,35) 

enter image description here

You can see that P in HP is below vertex 200. And also m on mpg is almost in line (or partially overlapping) from 0 to 20, leaving g in the middle of 20 and 25. I would think that the gap between H and P was would be in the middle (vertical) of 2 in 200. If that makes sense.

Adding multiple labels to the label (β€œHP”) helps fix this. Obviously, the name is centered on some coordinates, my guess is a β€œbox” that goes all the way to the bottom of the x labels (for the y title) and to the left of the y labels (for the x title). If you have them relative to the actual area of ​​the graph, it would be more desirable.

Is this achievable?

+6
source share
1 answer

In a @Hadley comment, since version 0.9.0, this error has been fixed:

 ggplot(mtcars, aes(x=mpg, y=hp)) + geom_point() + ylab("HP") + ylim(50,350) + xlim(10,35) 

gives:

enter image description here

+3
source

Source: https://habr.com/ru/post/902719/


All Articles