These statistical transformations (stats) adapt
conventional ggplot2 stats to one or the other matrix factor
of a tbl_ord, in lieu of stat_rows()
or stat_cols()
. They
accept the same parameters as their corresponding conventional
stats.
stat_rows_ellipse(
mapping = NULL,
data = NULL,
geom = "path",
position = "identity",
...,
type = "t",
level = 0.95,
segments = 51,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)stat_cols_ellipse(
mapping = NULL,
data = NULL,
geom = "path",
position = "identity",
...,
type = "t",
level = 0.95,
segments = 51,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
stat_rows_center(
mapping = NULL,
data = NULL,
geom = "point",
position = "identity",
show.legend = NA,
inherit.aes = TRUE,
...,
fun.data = NULL,
fun.center = NULL,
fun.min = NULL,
fun.max = NULL,
fun.args = list()
)
stat_cols_center(
mapping = NULL,
data = NULL,
geom = "point",
position = "identity",
show.legend = NA,
inherit.aes = TRUE,
...,
fun.data = NULL,
fun.center = NULL,
fun.min = NULL,
fun.max = NULL,
fun.args = list()
)
stat_rows_star(
mapping = NULL,
data = NULL,
geom = "segment",
position = "identity",
show.legend = NA,
inherit.aes = TRUE,
...,
fun.data = NULL,
fun.center = NULL,
fun.args = list()
)
stat_cols_star(
mapping = NULL,
data = NULL,
geom = "segment",
position = "identity",
show.legend = NA,
inherit.aes = TRUE,
...,
fun.data = NULL,
fun.center = NULL,
fun.args = list()
)
stat_rows_chull(
mapping = NULL,
data = NULL,
geom = "polygon",
position = "identity",
show.legend = NA,
inherit.aes = TRUE,
...
)
stat_cols_chull(
mapping = NULL,
data = NULL,
geom = "polygon",
position = "identity",
show.legend = NA,
inherit.aes = TRUE,
...
)
stat_rows_cone(
mapping = NULL,
data = NULL,
geom = "path",
position = "identity",
origin = FALSE,
show.legend = NA,
inherit.aes = TRUE,
...
)
stat_cols_cone(
mapping = NULL,
data = NULL,
geom = "path",
position = "identity",
origin = FALSE,
show.legend = NA,
inherit.aes = TRUE,
...
)
stat_rows_scale(
mapping = NULL,
data = NULL,
geom = "point",
position = "identity",
show.legend = NA,
inherit.aes = TRUE,
...,
mult = 1
)
stat_cols_scale(
mapping = NULL,
data = NULL,
geom = "point",
position = "identity",
show.legend = NA,
inherit.aes = TRUE,
...,
mult = 1
)
stat_rows_spantree(
mapping = NULL,
data = NULL,
geom = "segment",
position = "identity",
engine = "mlpack",
method = "euclidean",
show.legend = NA,
inherit.aes = TRUE,
...
)
stat_cols_spantree(
mapping = NULL,
data = NULL,
geom = "segment",
position = "identity",
engine = "mlpack",
method = "euclidean",
show.legend = NA,
inherit.aes = TRUE,
...
)
A ggproto layer.
Set of aesthetic mappings created by aes()
. If specified and
inherit.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.
The data to be displayed in this layer. There are three options:
If NULL
, the default, the data is inherited from the plot
data as specified in the call to ggplot()
.
A data.frame
, or other object, will override the plot
data. All objects will be fortified to produce a data frame. See
fortify()
for which variables will be created.
A function
will be called with a single argument,
the plot data. The return value must be a data.frame
, and
will be used as the layer data. A function
can be created
from a formula
(e.g. ~ head(.x, 10)
).
The geometric object to use to display the data for this layer.
When using a stat_*()
function to construct a layer, the geom
argument
can be used to override the default coupling between stats and geoms. The
geom
argument accepts the following:
A Geom
ggproto subclass, for example GeomPoint
.
A string naming the geom. To give the geom as a string, strip the
function name of the geom_
prefix. For example, to use geom_point()
,
give the geom as "point"
.
For more information and other ways to specify the geom, see the layer geom documentation.
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The position
argument accepts the following:
The result of calling a position function, such as position_jitter()
.
This method allows for passing extra arguments to the position.
A string naming the position adjustment. To give the position as a
string, strip the function name of the position_
prefix. For example,
to use position_jitter()
, give the position as "jitter"
.
For more information and other ways to specify the position, see the layer position documentation.
Additional arguments passed to ggplot2::layer()
.
The type of ellipse.
The default "t"
assumes a multivariate t-distribution, and
"norm"
assumes a multivariate normal distribution.
"euclid"
draws a circle with the radius equal to level
,
representing the euclidean distance from the center.
This ellipse probably won't appear circular unless coord_fixed()
is applied.
The level at which to draw an ellipse,
or, if type="euclid"
, the radius of the circle to be drawn.
The number of segments to be used in drawing the ellipse.
If FALSE
, the default, missing values are removed with
a warning. If TRUE
, missing values are silently removed.
logical. Should this layer be included in the legends?
NA
, the default, includes if any aesthetics are mapped.
FALSE
never includes, and TRUE
always includes.
It can also be a named logical vector to finely select the aesthetics to
display.
If FALSE
, 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, e.g. borders()
.
Functions and arguments
treated as in ggplot2::stat_summary()
, with fun.center
, fun.min
, and
fun.max
behaving as fun.y
, fun.ymin
, and fun.ymax
.
Logical; whether to include the origin with the transformed
data. Defaults to FALSE
.
Numeric value used to scale the coordinates.
A single character string specifying the package implementation
to use; "mlpack"
, "vegan"
, or "ade4"
.
Passed to stats::dist()
if engine
is "vegan"
or "ade4"
,
ignored if "mlpack"
.
The convenience function ord_aes()
can be used to incorporate all
coordinates of the ordination model into a statistical transformation. It
maps the coordinates to the custom aesthetics ..coord1
, ..coord2
, etc.
Some transformations, e.g. stat_center()
, are commutative with projection
to the 'x' and 'y' coordinates. If they detect aesthetics of the form
..coord[0-9]+
, then ..coord1
and ..coord2
are converted to x
and y
while any remaining are ignored.
Other transformations, e.g. stat_spantree()
, yield different results in a
planar biplot when they are computer before or after projection. If such a
stat layer detects these aesthetics, then the lot of them are used in the
transformation.
In either case, the stat layer returns a data frame with position aesthetics
x
and y
.
Other biplot layers:
biplot-geoms
,
stat_rows()
# compute row-principal components of scaled iris measurements
iris[, -5] %>%
prcomp(scale = TRUE) %>%
as_tbl_ord() %>%
mutate_rows(species = iris$Species) %>%
print() -> iris_pca
# row-principal biplot with centroids and confidence elliptical disks
iris_pca %>%
ggbiplot(aes(color = species)) +
theme_bw() +
geom_rows_point() +
geom_polygon(
aes(fill = species),
color = NA, alpha = .25, stat = "rows_ellipse"
) +
geom_cols_vector(color = "#444444") +
scale_color_brewer(
type = "qual", palette = 2,
aesthetics = c("color", "fill")
) +
ggtitle(
"Row-principal PCA biplot of Anderson iris measurements",
"Overlaid with 95% confidence disks"
)
Run the code above in your browser using DataLab