Re: White lines in geom_tile heatmap pdf-output

1,352 views
Skip to first unread message

David Kahle

unread,
Sep 25, 2012, 3:29:15 PM9/25/12
to skipperhoyer, ggp...@googlegroups.com
Have you tried geom_raster?  Are the lines in the saved pdf (png), or just in the tex'ed pdf?

david.

On Sep 25, 2012, at 2:22 PM, skipperhoyer wrote:

Hey!

I'm using knitr to write my thesis and I have a heatmap that I want to include. The plot is beautiful when I generate it from R, but when I make it "live" from latex / knitr, there are lots of very fine horizontal and vertical white lines.  The lines are present in the pdf text document as as the pdf file containing only the graph (the one that knitr makes).  I've played with the dpi settings in the knitr chunk, but that makes no difference.  Any ideas?

Minimal working example:

###
library(ggplot2)
library(reshape)
grid. <- do.call(rbind, lapply(1:100, function(x) rep(x, 100)))
heat <- melt(grid.)
ggplot(heat, aes(x = X1, y = X2)) + geom_tile(aes(fill = value))
###

The knitr options are:
\SweaveOpts{cache = TRUE, echo = FALSE, fig.align = "center", fig.width = 5, fig.height = 5, out.width = "0.7\\textwidth"}
and there are no local chunk options.

The pdf outputted by knitr (and imported into my text document pdf) is attached. How do I get rid of the white lines?? They don't seem to be particularly consistently spaced, nor do they line up with the underlying plot background. Looks like a visual artefact.

Thanks in advance!

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
<heat.pdf>

Winston Chang

unread,
Sep 25, 2012, 3:33:16 PM9/25/12
to skipperhoyer, ggp...@googlegroups.com
This is probably a function of your PDF viewer. I'm guessing you're viewing it with Preview.app on a Mac? When I view it in Chrome or in Adobe Reader, the lines aren't there.

I'm not sure exactly why this happens in Preview. Maybe it's a good question for the r-help or r-devel lists?

There's also a previous discussion about the topic on this list here:

-Winston

Benjamin Høyer

unread,
Sep 25, 2012, 3:37:59 PM9/25/12
to David Kahle, ggp...@googlegroups.com

I haven't tried geom_raster(), I'll check it out.

I just ran the graph (directly in R, not through latex/knitr) and saved to pdf, ggsave("heat.pdf") which still has the lines, but ggsave("heat.png") does not.  Using the knitr option dev = "png" solves the problem in my latex/knitr - but this seems like a bit of a hack.

Winston: I am using Sumatra on Windows 7.  I just opened the pdf in Adobe Reader and the plot looks fine!  How strange.

Shall I just concede that Sumatra has trouble showing pdf gradients?

Thanks,
Benjamin
--

Benjamin Høyer
+45 42403250

Reply all
Reply to author
Forward
0 new messages