guide_colbar | R Documentation |
Similar to guide_colourbar()
, this guide
displays continuous colour
or fill
aesthetics. It has additional options
to display caps at the end of the bar, depending on out-of-bounds values.
guide_colbar(
title = waiver(),
key = "auto",
first_guide = "axis_base",
second_guide = first_guide,
shape = "triangle",
size = NULL,
show = NA,
nbin = 15,
alpha = NA,
reverse = FALSE,
oob = scales::oob_keep,
theme = NULL,
vanilla = TRUE,
position = waiver(),
available_aes = c("colour", "fill")
)
title |
A |
key |
A sequence key specification. Defaults to
|
first_guide , second_guide |
Guides to flank the colour bar. Each guide can be specified using one of the following:
The |
shape |
A cap specification by providing one of the following:
|
size |
A |
show |
A |
nbin |
A positive |
alpha |
A |
reverse |
A |
oob |
An out-of-bounds handling function that affects the cap colour. Can be one of the following:
|
theme |
A |
vanilla |
A |
position |
A |
available_aes |
A |
As colours are always rendered as gradients, it is important to use a
graphics device that can render these. This can be checked by using
check_device("gradients")
.
A <Guide>
object
Other standalone guides:
guide_axis_base()
,
guide_axis_dendro()
,
guide_axis_nested()
,
guide_circles()
,
guide_colring()
,
guide_colsteps()
,
guide_legend_base()
,
guide_legend_cross()
,
guide_legend_group()
# A standard plot
p <- ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(colour = cty))
# The colourbar shows caps when values are out-of-bounds (oob)
p + scale_colour_viridis_c(
limits = c(10, NA),
guide = "colbar"
)
# It also shows how oob values are handled
p + scale_colour_viridis_c(
limits = c(10, NA), oob = scales::oob_squish,
guide = "colbar"
)
# Adjusting the type of cap
p + scale_colour_viridis_c(
limits = c(10, 30), oob = scales::oob_squish,
guide = guide_colbar(shape = "round")
)
# One-sided ticks
p + scale_colour_viridis_c(
guide = guide_colbar(second_guide = "none")
)
# Colour bar with minor breaks
p + scale_colour_viridis_c(
minor_breaks = scales::breaks_width(1),
guide = guide_colbar(key = "minor")
)
# Using log ticks on a colourbar
ggplot(msleep, aes(sleep_total, sleep_rem)) +
geom_point(aes(colour = bodywt), na.rm = TRUE) +
scale_colour_viridis_c(
transform = "log10",
guide = guide_colbar(key = "log")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.