Connect points to their centroid
stat_centroid.RdConnect points to their centroid.
Usage
stat_centroid(
mapping = NULL,
data = NULL,
geom = "segment",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
cfun = mean,
...
)Arguments
- mapping
Set of aesthetic mappings created by
aes()oraes_(). If specified andinherit.aes = TRUE(the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.- data
The data to be displayed in this layer. If NULL, the default, the data is inherited from the plot data as specified in the call to
ggplot().- geom
Use to override the default Geom
- position
Use to override the default position
- na.rm
If
FALSE, the default, missing values are removed with a warning. IfTRUE, missing values are silently removed.- show.legend
Logical. Should this layer be included in the legends?
NA, the default, includes if any aesthetics are mapped.FALSEnever includes, andTRUEalways includes. It can also be a named logical vector to finely select the aesthetics to display.- inherit.aes
TRUEorFALSE. IfFALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification.- cfun
Function used to calculate centroid location.
- ...
other arguments.
Examples
#----------------------------------------------------------------------------
# stat_centroid() examples
#----------------------------------------------------------------------------
library(bkstat)
library(ggplot2)
df <- data.frame(
group = c(rep("a", 5), rep("b", 5)),
x = rnorm(10),
y = rnorm(10)
)
ggplot(df, aes(x = x, y = y, color = group)) +
geom_point() +
stat_centroid()