View source: R/ch_add_stacked_labels.r
ch_add_stacked_labels | R Documentation |
This function adds ggrepel::geom_label_repel()
to a chart. It requires you
to specify the label aesthetic in the original ggplot. It also extends the
x-axis by a certain amount (20\
of the arguments get passed directly to ggrepel::geom_label_repel()
. This
expansion will combine with any other expansion present in the plot, such as
arguments based to ggplot2::scale_x_continuous()
. It needs to be used with a
%>%
and not a +
.
ch_add_stacked_labels(
.plot,
pct_extend = 1.2,
nudge_x = NULL,
segment.colour = NA,
min.segment.length = 0.1,
max.overlaps = 20,
segment.alpha = 0.5,
segment.size = 0.1,
hjust = "right",
direction = "y",
size = 3,
...
)
.plot |
(a |
pct_extend |
(numeric, default = |
nudge_x |
(numeric; default = NULL) Horizontal and vertical adjustments to nudge the starting position of each text label. |
segment.colour |
(character; default = NA) colour of the line segment, NA means no line segment |
min.segment.length |
Skip drawing segments shorter than this, as unit or
number. Defaults to 0.5. (Default unit is lines, but other units can be
specified by passing |
max.overlaps |
Exclude text labels when they overlap too many other things. For each text label, we count how many other text labels or other data points it overlaps, and exclude the text label if it has too many overlaps. Defaults to 10. |
segment.alpha |
(number; default = 0.5) the transparency of the line segment |
segment.size |
(number; default = 0.1) the size of the line segment |
hjust |
(default = "right") the horizontal justification of the label |
direction |
"both", "x", or "y" – direction in which to adjust position of labels |
size |
(number, default = 3) the size of the text in the label |
... |
other arguments passed to |
If you get a warning about Aesthetics not being the right length for size, that's a cryptic message telling you to set the size argument. Setting it to 3 usually looks alright.
a ggplot2
object
## Not run:
some_plot |> ch_add_stacked_labels()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.