I would like to be able to draw borders on geom_tile that do not overlap so that borders can convey their own information without confusing the viewer with disappearing borders.
library(ggplot2)
state <- data.frame(p=runif(100), x=1:10, y=rep(1:10, each=10), z=rep(1:5, each=20))
ggplot(state, aes(x, y)) +
geom_tile(aes(fill = p, color=as.factor(z)), size=2)

I trust you can see how confusing overlapping borders can be.
Use the width and height arguments to geom_tile to create space and prevent border overlap.
ggplot(state, aes(x, y)) +
geom_tile(aes(fill = p, color=as.factor(z), width=0.7, height=0.7), size=2)
I've created space between the tiles, but you can also adjust the width and height so that the borders just touch each other. Also, note that in my version of the graph the color legend for tiles does not have any colors. This is because the border color legend for geom_tile is broken in ggplot2 2.0. The problem has been fixed in the development version of ggplot2, but the fix hasn't been rolled out to CRAN yet. To get the development version, you can do devtools::install_github("hadley/ggplot2").
(Incidentally, if you're into optical illusions, the graph below creates the grid illusion).

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With