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

Inconsistency between generated pdf and png files #2407

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

Inconsistency between generated pdf and png files #2407

henrikmidtiby opened this issue Jan 18, 2018 · 6 comments
Labels
bug an unexpected problem or unintended behavior good first issue ❤️ good issue for first-time contributors help wanted ❤️ we'd love your help! layers 📈

Comments

@henrikmidtiby
Copy link

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
Copy link
Author

henrikmidtiby commented Jan 18, 2018

Generated png file
failure

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

@batpigandme
Copy link
Contributor

batpigandme commented Jan 18, 2018

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

png of pdf

@hadley
Copy link
Member

hadley commented Jan 18, 2018

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

@hadley hadley closed this as completed Jan 18, 2018
@wch
Copy link
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
Copy link
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.

@wch wch reopened this Jan 18, 2018
@hadley hadley added bug an unexpected problem or unintended behavior layers 📈 good first issue ❤️ good issue for first-time contributors help wanted ❤️ we'd love your help! labels Apr 26, 2018
@hadley hadley closed this as completed in 908d353 May 1, 2018
@lock
Copy link

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.
Labels
bug an unexpected problem or unintended behavior good first issue ❤️ good issue for first-time contributors help wanted ❤️ we'd love your help! layers 📈
Projects
None yet
Development

No branches or pull requests

4 participants