subguide_axis | R Documentation |
This is a sub-guide intended for annotating the thickness aesthetic
in ggdist. It can be used with the subguide
parameter of
geom_slabinterval()
.
Supports automatic partial function application.
subguide_axis(
values,
title = NULL,
breaks = waiver(),
labels = waiver(),
position = 0,
just = 0,
label_side = "topright",
orientation = "horizontal",
theme = theme_get()
)
subguide_inside(..., label_side = "inside")
subguide_outside(..., label_side = "outside", just = 1)
subguide_integer(..., breaks = scales::breaks_extended(Q = c(1, 5, 2, 4, 3)))
subguide_count(..., breaks = scales::breaks_width(1))
values |
Values used to construct the scale used for this guide.
Typically provided automatically by |
title |
The title of the scale shown on the sub-guide's axis. |
breaks |
One of:
|
labels |
One of:
|
position |
Numeric value between |
just |
Numeric value between |
label_side |
Which side of the axis to draw the ticks and labels on.
|
orientation |
Orientation of the geometry this sub-guide is for. One
of |
theme |
A ggplot2::theme object used to determine the style that the
sub-guide elements are drawn in. The title label is drawn using the
|
... |
Arguments passed to other functions, typically back to
|
subguide_inside()
is a shortcut for drawing labels inside of the chart
region.
subguide_outside()
is a shortcut for drawing labels outside of the chart
region.
subguide_integer()
only draws breaks that are integer values, useful for
labeling counts in geom_dots()
.
subguide_count()
is a shortcut for drawing labels where every whole number
is labeled, useful for labeling counts in geom_dots()
. If your max count is
large, subguide_integer()
may be better.
Other sub-guides:
subguide_none()
# example code
library(ggplot2)
library(distributional)
df = data.frame(d = dist_normal(2:3, 2:3), g = c("a", "b"))
# subguides allow you to label thickness axes
ggplot(df, aes(xdist = d, y = g)) +
stat_slabinterval(subguide = "inside")
# they respect normalization and use of scale_thickness_shared()
ggplot(df, aes(xdist = d, y = g)) +
stat_slabinterval(subguide = "inside", normalize = "groups")
# they can also be positioned outside the plot area, though
# this typically requires manually adjusting plot margins
ggplot(df, aes(xdist = d, y = g)) +
stat_slabinterval(subguide = subguide_outside(title = "density", position = "right")) +
theme(plot.margin = margin(5.5, 50, 5.5, 5.5))
# any of the subguide types will also work to indicate bin counts in
# geom_dots(); subguide_integer() and subguide_count() can be useful for
# dotplots as they only label integers / whole numbers:
df = data.frame(d = dist_gamma(2:3, 2:3), g = c("a", "b"))
ggplot(df, aes(xdist = d, y = g)) +
stat_dots(subguide = subguide_count(label_side = "left", title = "count")) +
scale_y_discrete(expand = expansion(add = 0.1)) +
scale_x_continuous(expand = expansion(add = 0.5))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.