Winawer Winawer - 1 month ago 4x
R Question

R ggplot: geom_tile lines in pdf output

I'm constructing a plot that uses geom_tile and then outputting it to .pdf (using pdf("filename",...)). However, when I do, the .pdf result has tiny lines (striations, as one person put it) running through it. I've attached an image showing the problem. Minimal example

Googling let to this thread, but the only real advice in there was to try passing size=0 to geom_tile, which I did with no effect. Any suggestions on how I can fix these? I'd like to use this as a figure in a paper, but it's not going to work like this.

Minimal code:


volcano3d <- melt(volcano)
names(volcano3d) <- c("x", "y", "z")
v <- ggplot(volcano3d, aes(x, y, z = z))

print(v + geom_tile(aes(fill=z)) + stat_contour(size=2) + scale_fill_gradient("z"))


This happens because the default colour of the tiles in geom_tile seems to be white.

To fix this, you need to map the colour to z in the same way as fill.

print(v + 
  geom_tile(aes(fill=z, colour=z), size=1) + 
  stat_contour(size=2) + 

enter image description here