Skip to content

Line weights/colors don't look right with theme_bw() and facets #1786

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

Closed
wch opened this issue Sep 27, 2016 · 10 comments
Closed

Line weights/colors don't look right with theme_bw() and facets #1786

wch opened this issue Sep 27, 2016 · 10 comments
Assignees
Milestone

Comments

@wch
Copy link
Member

wch commented Sep 27, 2016

The panels have a bit of a raised, 3-D look to them. Also, the thinner/lighter lines on the left side look a bit off when the facet label box has a darker/heavier line.

ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  facet_grid(am ~ cyl) +
  theme_bw()

image

@hadley
Copy link
Member

hadley commented Sep 27, 2016

@jiho @thomasp85 any ideas? Did clipping change?

@thomasp85
Copy link
Member

clipping might have changed, but I'm unable to reproduce the look on my computer... I'll go through the old clipping specs and see if I can find anything. but I might need you to verify...

@thomasp85 thomasp85 self-assigned this Sep 27, 2016
@wch
Copy link
Member Author

wch commented Sep 27, 2016

This is on my Ubuntu machine.

@thomasp85
Copy link
Member

Can you check with the CRAN version and see if the look is ok there?

@wch
Copy link
Member Author

wch commented Sep 27, 2016

Hm, it looks different depending on the R version and graphics device. This is probably too much information, but here you go. For each of the code snippets, I'll include two screenshots: one for ggplot2 2.1.0 and one for the latest dev version, 2.1.0.9000 (1ee809a).

Calling png() in a terminal

p <- ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  facet_grid(am ~ cyl) +
  theme_bw()

# Using default png() settings
png('test-terminal.png', width = 600, height = 400)
print(p)
dev.off()

test-terminal

test-terminal

This is using Cairo::CairoPNG for the output:

Cairo::CairoPNG('test-terminal-Cairo.png', width = 600, height = 400)
print(p)
dev.off()

test-terminal-cairo

test-terminal-cairo

This is what it looks like in the RStudio viewer pane if I just print it:

p

image

image

And this is what it looks like in RStudio if I click on Export->Copy to Clipboard:

image

image

I suspect the layering of objects has changed, and the different devices treat it differently.

If you're on a Mac and you want to get similar output to my png(), I believe you need to run png(type="cairo").

@thomasp85
Copy link
Member

Thanks - I'll dig into it tomorrow

@jiho
Copy link
Contributor

jiho commented Sep 27, 2016

The darker lines are my doing, so that they match the ticks. But the clipping definitely changed. For completeness here is the aspect with 2.1.0 (on left) and current master (on right) on OS X.

screen shot 2016-09-27 at 23 50 50

The clipping of the sides of the panel was already a bit "too much" in 2.1.0 but not as noticeable because the color was lighter. However, the outline of the facets used to be clipped too. And it was when I tested the color change in #1679 (see the second plot). With the outline not clipped, the aspect is indeed weird. This is also a problem with theme_classic(), which has outlines on facet labels.

screen shot 2016-09-27 at 23 54 41

@thomasp85
Copy link
Member

Ok, it's clear that this is my wrongdoing :-)

@jiho
Copy link
Contributor

jiho commented Sep 28, 2016

That said, if you could clip the content of the background panel + the grid lines (which need to be clipped of course) but not the outline of the panel or axes, it would make it easier to design themes. For example matching the thickness of the axes with the thickness of the grid lines is difficult/impossible now because axes are clipped and grid lines are not (basically one has to make axes twice as thick and even then, it is not an exact match). It will also help get a smoother, more homogeneous look in various rendering engines. As Winston's examples above show, with rendering engines which favour sharpness (i.e. not OS X's but nearly all others), the clipped lines can appear of different width depending how the rendering engine rounds the number of pixels. Finally, it also makes the outline of facet labels very square (because it is clipped) when one might want a smoother look, with rounded angles.

This would require some tweaking of the themes to keep the current aspect but we could easily do this in concert.

@thomasp85
Copy link
Member

@wch Can you check out #1789. I did make an error with the new strip constructors so they weren't clipped, but apart from that I could not elicit any change by making stacking and clipping more explicit - I think the panel-border effect is simply an artefact of the new theme settings by @jiho and bad rendering...

@thomasp85 thomasp85 added this to the v2.2.0 milestone Sep 28, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 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

No branches or pull requests

4 participants