Skip to content

Add descenders to heights #1728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 24, 2016
Merged

Add descenders to heights #1728

merged 5 commits into from
Aug 24, 2016

Conversation

hadley
Copy link
Member

@hadley hadley commented Aug 23, 2016

And increase margins slightly. Fixes #1712

@baptiste, @thomasp85, @jiho – can you please take a look? I always forget the consequences of tweaking theme defaults.

library(ggplot2)
df <- data.frame(x = 1:9, y = 1:9)

ggplot(df, aes(x, y)) + 
  geom_point() + 
  labs(
    y = "yyy",
    title = "This is title yyyyyy",
    subtitle = "This is a subtitle yyyyyy"
  )

Before:
before

After:
after

The difference is subtle, but an improvement.

And increase margins slightly. Fixes #1712
@jiho jiho mentioned this pull request Aug 23, 2016
@jiho
Copy link
Contributor

jiho commented Aug 23, 2016

I like the change.

With descenders taken into account, I think the extra space may not be needed (I prefer more room for the data and less for the legends).
In particular, I would put the left margin of axis.title.y and the bottom margin of axis.title.x to 0. This way, when setting plot.margin to 0, the titles are flush with the border of the plot, like the panel background and the main title are. I usually want this for plots inserted within a text, so that the left of the y axis title aligns exactly with the left of the paragraphs and the x axis falls on the baseline if the height of the plot is correctly computed.
Regarding the 0.8 * half_line vs. half_line for the other margin I have no strong opinion.

This is the current with branch descenders
1
and this has the outer margins at 0
2
and this would be with outer margins at 0 and plot.margin at 0 (with titles with ascenders and descenders):
3
(open the images to better see the position with respect to the margin).

@hadley
Copy link
Member Author

hadley commented Aug 23, 2016

The top of the T gets cut off in the last plot, but I could certainly drop the outer padding to something nominal like 0.1.

margin = margin(r = half_line, l = half_line / 2),
vjust = 1
margin = margin(r = half_line),
vjust = 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the added comma is problematic here. It should create an error.

@jiho
Copy link
Contributor

jiho commented Aug 24, 2016

Indeed, the top of capitals or ascenders and the bottom of descenders are slightly cut off (although that depends on the rendering software; when I import the PDF into Inkscape and re-export it, the clipping of letters is not as pronounced). And indeed, I think the solution is to set plot.margin at 0.1 instead of 0, rather than add outer margins the to various outer plot elements (because you would need to add it to the title but also to the panel if there is no title etc.).

So basically, the changes look perfect to me now.

@jiho
Copy link
Contributor

jiho commented Aug 24, 2016

There was a way at some point to change the position of the axes (put the x axis on top, the y axis on the right, etc.). See https://groups.google.com/forum/?fromgroups=#!topic/ggplot2-dev/JkJU5CLBkQw

Is that not relevant anymore? If such tweaks exist then, ideally, there should be a way in the themes to specify "outer margin" instead of left/right/top/bottom margin. The easy alternative of course would be to make margins symmetrical, but I would be less pleasing visually as explained above.

@thomasp85
Copy link
Member

This is not currently possible, but depending on the complexity it might be included in the facet rewrite (with @hadley's blessing of course)

with regards to margins, see my comment on #1727 - optimally this proposal should be implemented for all margin settings and would allow for symmetric margin setting

@hadley
Copy link
Member Author

hadley commented Aug 24, 2016

I think the theming system is already sufficiently complicated without having to additionally distinguish between inner/outer. The unfortunate reality is that if you have a theme where the labels are in a different place you will have to tweak margin settings in numerous locations. I don't think there is a good solution for this apart from implementing a full constraint-based layout system.

@hadley hadley merged commit c8086c3 into master Aug 24, 2016
mnbram pushed a commit to mnbram/ggplot2 that referenced this pull request Aug 26, 2016
* Add descenders to heights

And increase margins slightly. Fixes tidyverse#1712

* Add issue number

* Update theme test

* Reduce outer margins
@hadley hadley deleted the descenders branch May 10, 2018 17:03
@lock
Copy link

lock bot commented Nov 6, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Nov 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants