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

saved PDFs of rasters interpolate in some viewers #1707

Closed
davharris opened this issue Aug 12, 2016 · 3 comments
Closed

saved PDFs of rasters interpolate in some viewers #1707

davharris opened this issue Aug 12, 2016 · 3 comments

Comments

@davharris
Copy link
Contributor

davharris commented Aug 12, 2016

The code below creates a simple raster with 18 sharply-defined cells. If I ggsave it as a .png, I get a file that always renders correctly:

image

But if I save it as a .pdf, I get different behavior in different viewers. In Google Chrome, it renders like the .png. But in Apple Preview, it looks like this screenshot:

image

I get this behavior even if I explicitly set interpolate=FALSE in geom_raster, and regardless of the value I set for dpi, and various arguments to pdf like compress and onefile. I also get the same behavior if I "save as PDF" from the RStudio GUI.

I don't speak PDF/postscript, so I'm not sure how to diagnose this, but I'd be happy to provide additional information if for some reason this isn't reproducible on your machine.

Code

library(ggplot2)

data = data.frame(
  x = c(1L, 1L, 1L, 1L, 2L, 2L, 
        2L, 2L, 3L, 3L, 3L, 3L, 3L, 2L, 1L, 3L, 2L, 1L), 
  y = c(2L, 4L, 5L, 6L, 2L, 4L, 5L, 6L, 2L, 4L, 5L, 6L, 1L, 1L, 1L, 
        3L, 3L, 3L),
  fill = c(1, 0.85, 0.98, 0.92, 0.97, 0.88, 0.93, 0.88, 0.77, 0.9, 0.98, 
           0.87, 0.73, 0.5, 0.45, 0.48, 0.52, 0.8)
)

ggplot(data, aes(x = factor(x), y = factor(y), fill = fill)) +
  geom_raster()

ggsave("Rplot.pdf", ggplot(data, aes(x = factor(x), y = factor(y), fill = fill)) +
         geom_raster())

ggsave("Rplot.png", ggplot(data, aes(x = factor(x), y = factor(y), fill = fill)) +
         geom_raster())

SessionInfo:

R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_2.1.0

loaded via a namespace (and not attached):
 [1] labeling_0.3     colorspace_1.2-6 scales_0.4.0     plyr_1.8.4      
 [5] rsconnect_0.4.3  tools_3.3.1      gtable_0.2.0     Rcpp_0.12.6     
 [9] grid_3.3.1       digest_0.6.10    munsell_0.4.3 

Files

https://cloud.githubusercontent.com/assets/843017/17610634/d981671a-600d-11e6-8211-b23fc216dda9.png

https://github.com/hadley/ggplot2/files/414529/Rplot.pdf

@davharris
Copy link
Contributor Author

Sorry, looks like this is a duplicate of #417. If so, feel free to close it. Sorry for taking up your time!

@davharris
Copy link
Contributor Author

On the other hand, if you think it would be useful, I'd be happy to write a PR that adds a line to ?geom_raster describing the issue and the geom_tile workaround so that nobody else wastes your time with this.

(sorry for the triple post!)

@hadley
Copy link
Member

hadley commented Aug 12, 2016

I corresponded with @pmur002 about this some time back - as far as we can tell the pdf is being written correctly (i.e. it contains a don't interpolate flag), and it's the viewer that's buggy.

@hadley hadley closed this as completed Aug 12, 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.
Projects
None yet
Development

No branches or pull requests

3 participants