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

Inconsistency between generated pdf and png files #2407

Closed
henrikmidtiby opened this Issue Jan 18, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@henrikmidtiby

henrikmidtiby commented Jan 18, 2018

I have observed an inconsistency between the generated pdf and png files in the plot below.
In the plot I insert an annotate object with the type 'label'; where the width of the black line around the label is set to zero.
This works fine when exporting to a png file.
But when I export the plot to a pdf file, the black line is still present.

library(tidyverse)
#> ── Attaching packages ──────────────────────────────────────────────────── tidyverse 1.2.1 ──
#> ✔ ggplot2 2.2.1     ✔ purrr   0.2.4
#> ✔ tibble  1.4.1     ✔ dplyr   0.7.4
#> ✔ tidyr   0.7.2     ✔ stringr 1.2.0
#> ✔ readr   1.1.1     ✔ forcats 0.2.0
#> ── Conflicts ─────────────────────────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag()    masks stats::lag()
p <- tibble() %>%
  ggplot() + 
  annotate('label', x = 1, y = 0, 
           label='is there a border around this label?', 
           label.size=0)

# In the generated pdf file, there is a black border around the inserted label.
# I don't think that this is the intended behaviour.
ggsave('failure.pdf', p, 
       height = 3, width=7)

# In the generated png file, there is no border around the inserted label.
# I think that this is the intended behaviour.
ggsave('failure.png', p, 
       height = 3, width=7)
@henrikmidtiby

This comment has been minimized.

henrikmidtiby commented Jan 18, 2018

Generated png file
failure

Genrated pdf file (which contains the error)
failure.pdf

@batpigandme

This comment has been minimized.

Member

batpigandme commented Jan 18, 2018

That is strange. For convenience/browsability, here's a picture of the pdf.

png of pdf

@hadley

This comment has been minimized.

Member

hadley commented Jan 18, 2018

Any difference in rendering between graphics devices is unfortunately outside the scope of ggplot2

@hadley hadley closed this Jan 18, 2018

@wch

This comment has been minimized.

Member

wch commented Jan 18, 2018

This is probably due to a bug in grid's roundrectGrob. Here's an example that has a similar problem:

library(grid)

png("test.png")
grid.newpage()
l <- grid.roundrect(width=.5, height=.5,
  gp = gpar(col = "black", fill = "grey90", lwd = 0)
)
grid.draw(l)
dev.off()

pdf("test.pdf")
grid.newpage()
l <- grid.roundrect(width=.5, height=.5,
  gp = gpar(col = "black", fill = "grey90", lwd = 0)
)
grid.draw(l)
dev.off()
@wch

This comment has been minimized.

Member

wch commented Jan 18, 2018

Actually, now that I look at this some more, I believe the problem is that PDF renderers often display a hairline for zero-width lines. For example, this has a visible line:

pdf("test.pdf")
plot(cars, type = "l", lwd = 0)
dev.off()

The reason that this hasn't been a problem with other geoms is because many of them have a default color of NA, which results in no line at all. Here's GeomRect, and here's GeomLabel.

I suggest changing GeomLabel to set the col to NA when label.size is 0.

@lock

This comment has been minimized.

lock bot commented Oct 28, 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 Oct 28, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.