# geom_rectmargin() is parameterised by the four corners
df <- data.frame(
xmin = c(1, 5),
xmax = c(2, 7),
ymin = c(1, 2),
ymax = c(2, 4),
fill = c("A", "B")
)
ggplot(df, aes(xmin = xmin, xmax = xmax,
ymin = ymin, ymax = ymax,
fill = fill)) +
geom_rect() +
geom_rectmargin()
# geom_tilemargin() is parameterised by center and size
df <- data.frame(
x = c(1, 4),
y = c(1, 2),
width = c(2, 1),
height = c(1, 2),
fill = c("A", "B")
)
ggplot(df, aes(x, y,
width = width, height = height,
fill = fill)) +
geom_tile() +
geom_tilemargin()
Run the code above in your browser using DataLab