# Combine any two position aesthetics
df <- data.frame(
x = c(1.5, 3.5), xmin = c(1, 2),
y = c(1.5, 2.5), ymin = c(1, 2)
)
ggplot(df) +
geom_box(aes(x = x, xmin = xmin, y = y, ymin = ymin))
# Works with partial information for position, as long as two aesthetics
# are complete for any observation.
df <- data.frame(
x = c(1.5, NA, 4), xmin = c(1, 2, NA), width = c(NA, 3, 2),
y = c(1.5, 2.5, NA), ymin = c(NA, 2, 3), height = c(1, NA, 3)
)
ggplot(df) +
geom_box(aes(x = x, xmin = xmin, y = y, ymin = ymin,
width = width, height = height))
# Set radius for rounded corners
ggplot() +
geom_box(
aes(x = 1:3, width = rep(1, 3),
y = 1:3, height = 3:1),
radius = 5
)
Run the code above in your browser using DataLab