geom_tileborder {desplot} | R Documentation |
Borders between tiles
Description
'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.
Usage
geom_tileborder(
mapping = NULL,
data = NULL,
geom = "segment",
position = "identity",
na.rm = TRUE,
show.legend = NA,
inherit.aes = TRUE,
...
)
Arguments
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 to display the data, either as a
|
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
Details
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)'.
Examples
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)