nzcoops
nzcoops

Reputation: 9380

Position of axis titles in ggplot, relative placement?

Does anyone have any insight into the placement of the axis titles 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 the P in HP is below the top of the 200. And likewise the m on mpg is almost in line (or partly overlapping) with the 0 on 20 leaving the g in the middle of 20 and 25. I would have thought the middle of the gap between the H and P would have been in the middle (vertically) of the 2 in 200. If that makes sense.

Adding a few spaces to the label (" HP") helps to fix it. Obviously the title is being centered relative to some co-ordinates, 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). When having them relative to the actual plotting area would be more desirable.

Is this achievable?

Upvotes: 6

Views: 2477

Answers (1)

joran
joran

Reputation: 173547

Per @Hadley's comment, as of version 0.9.0 this bug-let has been fixed:

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

produces:

enter image description here

Upvotes: 3

Related Questions