View source: R/stat-referent.r
stat_referent | R Documentation |
Compute statistics with respect to a reference data set with shared positional variables.
stat_referent(
mapping = NULL,
data = NULL,
geom = "blank",
position = "identity",
referent = NULL,
show.legend = NA,
inherit.aes = TRUE,
...
)
## S3 method for class 'LayerRef'
ggplot_add(object, plot, object_name)
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 for this layer.
When using a
|
position |
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
|
referent |
The reference data set; see Details. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Additional arguments passed to |
object |
An object to add to the plot |
plot |
The ggplot object to add |
object_name |
The name of the object to add |
Often in geometric data analysis a statistical transformation applied to data
X
will also depend on data Y
, for example when drawing the
projections of vectors X
onto vectors Y
. The stat layer
stat_referent()
accepts Y
as an argument to the referent
parameter
and pre-processes them using the existing positional aesthetic mappings to
x
and y
.
The ggproto can be used as a parent to more elaborate statistical
transformations, or the stat can be paired with geoms that expect the
referent
parameter and use it to position their transformations of X
.
It pairs by default to [ggplot2::geom_blank()]
so as to prevent possibly
confusing output.
A ggproto layer.
Other biplot layers:
biplot-geoms
,
biplot-stats
,
stat_rows()
# simplify the Motor Trends data to two predictors legible at aspect ratio 1
mtcars |>
transform(hp00 = hp/100) |>
subset(select = c(mpg, hp00, wt)) ->
subcars
# compute the gradient of `mpg` against these two predictors
lm(mpg ~ hp00 + wt, subcars) |>
coefficients() |>
as.list() |> as.data.frame() ->
grad
# use the gradient as a reference (to no effect in this basic ggproto)
ggplot(subcars, aes(x = hp00, y = wt)) +
coord_equal() +
geom_point() +
stat_referent(referent = grad)
ggplot(subcars, aes(x = hp00, y = wt)) +
coord_equal() +
stat_referent(geom = "point", referent = grad)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.