View source: R/geom_tileborder.R
geom_tileborder | R Documentation |
'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 to display the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.