tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.51k stars 2.03k forks source link

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

Closed wch closed 8 years ago

wch commented 8 years ago

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 commented 8 years ago

@jiho @thomasp85 any ideas? Did clipping change?

thomasp85 commented 8 years ago

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...

wch commented 8 years ago

This is on my Ubuntu machine.

thomasp85 commented 8 years ago

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

wch commented 8 years ago

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 commented 8 years ago

Thanks - I'll dig into it tomorrow

jiho commented 8 years ago

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 commented 8 years ago

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

jiho commented 8 years ago

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 commented 8 years ago

@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...