Skip to content
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

Use rel() more consistently in theme elements, take two #2173

Merged
merged 4 commits into from
Jun 21, 2017

Conversation

karawoo
Copy link
Member

@karawoo karawoo commented Jun 19, 2017

This is the continuation of #1883. Includes @baptiste's changes plus a line in NEWS.md about the change.

@karawoo karawoo requested a review from hadley June 19, 2017 18:04
@karawoo
Copy link
Member Author

karawoo commented Jun 19, 2017

Hmm, I'm surprised the Travis build passed. It looks like this change breaks the visual tests in test-theme.r. Some of the panel grid lines are a little lighter now. Here are some screenshots from vdiffr::manage_cases()

Before:

screen shot 2017-06-19 at 11 23 54 am

After:

screen shot 2017-06-19 at 11 24 05 am

@@ -134,7 +134,7 @@ theme_grey <- function(base_size = 11, base_family = "") {
panel.background = element_rect(fill = "grey92", colour = NA),
panel.border = element_blank(),
panel.grid.major = element_line(colour = "white"),
panel.grid.minor = element_line(colour = "white", size = 0.25),
panel.grid.minor = element_line(colour = "white", size = rel(0.25)),
Copy link
Member

Choose a reason for hiding this comment

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

I noticed that these actually change the values of the width as the base_size (as far as I can tell) is set to 0.5 by line. I think that means all the values inside rel() should be doubled.

It also suggests that before merging this PR we should make some basic visual tests for the themes.

Copy link
Member

Choose a reason for hiding this comment

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

Ooops, should've refreshed before commenting. Glad the tests picked this up! (Although I'm not sure what went wrong on travis)

@karawoo
Copy link
Member Author

karawoo commented Jun 19, 2017

I doubled the values inside rel() and that indeed fixed the failing visual tests on my machine. theme_linedraw() doesn't have an associated visual test, so making this change for that theme didn't affect anything testing-wise. Should I add a test for this one?

@has2k1
Copy link
Contributor

has2k1 commented Jun 19, 2017

Tests failed on travis but not on appveyor, this is similar to #2080.

@@ -204,15 +204,15 @@ theme_linedraw <- function(base_size = 11, base_family = "") {
theme_bw(base_size = base_size, base_family = base_family) %+replace%
theme(
# black text and ticks on the axes
axis.text = element_text(colour = "black", size = rel(0.8)),
axis.ticks = element_line(colour = "black", size = 0.25),
axis.text = element_text(colour = "black", size = rel(1.6)),
Copy link
Member

Choose a reason for hiding this comment

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

I think this should stay as is since it was already in a rel()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops yes, will change it back.

@hadley
Copy link
Member

hadley commented Jun 19, 2017

@karawoo do you mind doing a separate PR that ensures that there's one visual test for each theme that's bundled with ggplot2? Then we can re-run this on top of that, and be confident that we haven't changed anything accidentally.

@baptiste
Copy link
Contributor

baptiste commented Jun 19, 2017

My original reason to look at this piece of source code and notice inconsistencies was triggered by a small plot in the margin of a Tufte-style document that looked quite bad/disproportionate. I think it may be worth setting up visual tests for a couple of different plot sizes, e.g. i) a 4x3 inches figure with 11pt font etc. for a typical publication, ii) a 24pt font, bold lines, 8x4in plot for a powerpoint, iii) a small inset-style / margin figure with 9pt font and thin lines.

(last time I looked, some themes had a few default aesthetics that I found visually suboptimal at small sizes):
https://gist.github.com/baptiste/8db48ede1eacb22cdd78093f715cb945

baptiste and others added 3 commits June 20, 2017 16:34
Small plots (e.g. in the margins of tufte-style books) tend to look heavy with the current linewidth settings, and after investigating I noticed some inconsistencies in the use of `rel()`.
@karawoo
Copy link
Member Author

karawoo commented Jun 20, 2017

I rebased these changes now that we've got the new test from #2174.

NEWS.md Outdated
@@ -1,5 +1,7 @@
# ggplot2 2.2.1.9000

* Uses `rel()` more consistently in theme defaults (@baptiste).
Copy link
Member

Choose a reason for hiding this comment

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

I think you can be a bit more explicit: use rel() to set line widths in theme defaults.

@baptiste
Copy link
Contributor

This discussion got me thinking about an analogy to optical sizes for rendering fonts, whereby different characters undergo minute changes in specific size ranges, to improve legibility and aesthetics. I wonder if the theme system couldn't use a similar strategy to adjust line widths, font sizes, perhaps even colour and fills, depending on a global parameter (plot size is what comes to mind).

In another aspect, rel() could perhaps be extended to colours, so that one could specify a "foreground" and "background" parent colour, and the children elements would relate to that harmoniously (using either faded tones, complementarity, etc. types of palettes). That's more or less the concept used in Beamer themes.

rel() could perhaps also gain optional arguments to set an absolute min/max value, e.g. rel(0.25, min=0.1) would ensure that the linewidth would never be thinner than 0.1mm (sometimes a requirement of Editors).

@karawoo karawoo merged commit 2907cf5 into tidyverse:master Jun 21, 2017
@karawoo karawoo deleted the linewidths-rel branch June 21, 2017 17:12
@lock
Copy link

lock bot commented Jan 18, 2019

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 Jan 18, 2019
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.

4 participants