# A standard plot
p <- ggplot(mpg, aes(displ, hwy, colour = cty)) +
geom_point()
# Just some recangles
p + scale_colour_viridis_c(guide = gizmo_stepcap())
# Caps show up when there is data outside the limits
p + scale_colour_viridis_c(
limits = c(10, 30),
guide = gizmo_stepcap()
)
# The scale's out-of-bounds handler determines cap colour
p + scale_colour_viridis_c(
limits = c(10, 30), oob = scales::oob_squish,
guide = gizmo_stepcap()
)
# Customising the display of the guide
p +
scale_colour_viridis_c(
oob = scales::oob_squish,
guide = gizmo_stepcap(
shape = "round", show = c(FALSE, TRUE),
size = unit(1, "cm"),
theme = theme(legend.key.height = unit(4, "cm"))
)
) +
theme(
legend.frame = element_rect(colour = "black"),
legend.key.width = unit(0.5, "cm")
)
Run the code above in your browser using DataLab