Spacing between ticks and axis labels

6,743 views
Skip to first unread message

Edward Schwartz

unread,
Nov 19, 2013, 4:01:55 PM11/19/13
to ggp...@googlegroups.com
Hi,

It seems that there is no way to adjust the space between tick labels and axis labels. This seems to be a long standing problem [1].  Would it be possible to add a new margin for this, such as there is between the tick marks and the tick labels?

I am producing a figure that has large fonts for a slide.  Unfortunately, this makes the spacing between the tick labels and axis labels seem inadequate.  Using vjust helps a little bit, but is still not great.  Here's what I have right now [2].

Thanks for your consideration!

Ista Zahn

unread,
Nov 20, 2013, 10:20:56 AM11/20/13
to Edward Schwartz, ggplot2
You can in fact pass negative values to vjust (this feels dirty, as
the documentation states that these values must be in the [0, 1]
range, but it works). Passing vjust = -5 works:

ggplot(mtcars, aes(x=hp, y=mpg)) +
geom_point() +
theme(axis.title.x = element_text(vjust=-5))

except that the title is now outside the plotting area, so we also
have to increase the plot.margin:

library(grid)
ggplot(mtcars, aes(x=hp, y=mpg)) +
geom_point() +
theme(axis.title.x = element_text(vjust=-5) ,
plot.margin = (unit(c(.5, .5, 2, .5), "cm")))

HTH,
Ista
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Edward Schwartz

unread,
Nov 20, 2013, 11:32:05 AM11/20/13
to ggp...@googlegroups.com, Edward Schwartz
Hi Ista,

Thank you for the workaround.  I'll try this out on my graph.

I still think there should be an additional margin setting, though.  There are two problems with vjust hacks:

1. The vjust value is unintuitive to adjust.  At least for me, I just keep adjusting it until the graph looks "right".  A margin is specified in units which are easy to understand, and don't depend on the height/width of the text area.

2. Manually adjusting the plot margins should not be needed!

I'd be happy to develop a patch for this if there is any interest in incorporating it into ggplot2.

Ed
Reply all
Reply to author
Forward
0 new messages