stat_funxy | R Documentation |
The function xy stat applies a function to the x- and y-coordinates of a
layers positions by group. The stat_centroid()
and
stat_midpoint()
functions are convenience wrappers for calculating
centroids and midpoints. stat_funxy()
by default leaves the data
as-is, but can be supplied functions and arguments.
stat_funxy(
mapping = NULL,
data = NULL,
geom = "point",
position = "identity",
...,
funx = force,
funy = force,
argx = list(),
argy = list(),
crop_other = TRUE,
show.legend = NA,
inherit.aes = TRUE
)
stat_centroid(
...,
funx = mean,
funy = mean,
argx = list(na.rm = TRUE),
argy = list(na.rm = TRUE)
)
stat_midpoint(..., argx = list(na.rm = TRUE), argy = list(na.rm = TRUE))
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data, either as a
|
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
... |
Other arguments passed on to |
funx , funy |
A |
argx , argy |
A named |
crop_other |
A |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
This statistic only makes a minimal attempt at ensuring that the results from calling both functions are of equal length. Results of length 1 are recycled to match the longest length result.
A StatFunxy
ggproto object, that can be added to a plot.
p <- ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species))
# Labelling group midpoints
p + geom_point() +
stat_midpoint(aes(label = Species, group = Species),
geom = "text", colour = "black")
# Drawing segments to centroids
p + geom_point() +
stat_centroid(aes(xend = Sepal.Width, yend = Sepal.Length),
geom = "segment", crop_other = FALSE)
# Drawing intervals
ggplot(iris, aes(Sepal.Width, Sepal.Length, colour = Species)) +
geom_point() +
stat_funxy(geom = "path",
funx = median, funy = quantile,
argy = list(probs = c(0.1, 0.9)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.