`geom_tileborder` draws a border between tiles of different classes. The required aesthetics are `aes(x,y,grp)`, where `grp` is the grouping classification that separates tiles.
geom_tileborder( mapping = NULL, data = NULL, geom = "segment", position = "identity", na.rm = TRUE, show.legend = NA, inherit.aes = TRUE, ... )
mapping | Set of aesthetic mappings created by |
---|---|
data | The data to be displayed in this layer. There are three options: If A A |
geom | The geometric object to use display the data |
position | Position adjustment, either as a string, or the result of a call to a position adjustment function. |
na.rm | If |
show.legend | logical. Should this layer be included in the legends?
|
inherit.aes | If |
... | Other arguments passed on to |
Note, we cannot use `aes(group)` because it groups the interaction of ALL discrete variables including facets. Since we do not want to draw a border between facets, we had to define a new aesthetic. See: # http://ggplot2.tidyverse.org/reference/aes_group_order.html
Also, we do not want to split the data into separate groups for each level of `grp`, so we need to include `aes(group=1)`.
dd <- data.frame( x=c(1,2,1,2,3,1,2,1,2,3), y=c(2,2,2,2,2,1,1,1,1,1), loc=factor(c(1,1,2,2,2,1,1,2,2,2)), rep=factor(c(2,2,1,2,3,1,1,1,2,3))) library(ggplot2) ggplot(dd, aes(x=x, y=y)) + facet_wrap( ~ loc) + geom_tile(aes(fill=rep)) + geom_tileborder(aes(group=1, grp=rep), lwd=1.5)# Compare to lattice version of desplot # desplot::desplot(rep ~ x*y|loc, data=dd, out1=rep)