| stat_rule | R Documentation |
Determine axis limits and offset vectors from reference data.
stat_rule(
mapping = NULL,
data = NULL,
geom = "rule",
position = "identity",
fun.lower = "minpp",
fun.upper = "maxpp",
fun.offset = "minabspp",
fun.args = list(),
referent = NULL,
show.legend = NA,
inherit.aes = TRUE,
...
)
minpp(x, p = 0.1)
maxpp(x, p = 0.1)
minabspp(x, p = 0.1)
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
|
fun.lower, fun.upper, fun.offset |
Functions used to determine the limits
of the rules and the translations of the axes from the projections of
|
fun.args |
Optional additional arguments passed on to the functions. |
referent |
The reference data set, admitting the same 3 options as
|
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Additional arguments passed to |
x |
A numeric vector. |
p |
A numeric value; the proportion of a range used as a buffer. |
Biplots with several axes can become cluttered and illegible. When this happens, Gower, Gardner–Lubbe, & le Roux (2011) recommend to translate the axes to a new point of intersection away from the origin, adjusting the axis markers accordingly. Then the axes converge in a region of the plot offset from most position markers or other elements. An alternative solution, implemented in the bipl5 package (https://github.com/RuanBuys/bipl5), is to translate each axis orthogonally away from the origin, which preserves the axis markers. This is the technique implemented here.
Separately, axes that fill the plotting window are uninformative when they exceed the range of the plotted position markers projected onto them. They may even be misinformative, suggesting that linear relationships extrapolate outside the data range. In these cases, Gower and Harding (1988) recommend using finite ranges determined by the data projection onto each axis.
Three functions control these operations: fun.offset computes the
orthogonal distance of each axis from the origin, and fun.lower and
fun.upper compute the distance along each axis of the endpoints to the
(offset) origin. Both functions depend on what position data is to be offset
from or limited to, which must be passed manually to the referent
parameter.
A ggproto layer.
This statistical transformation is done with respect to reference data passed
to referent (ignored if NULL, the default, possibly resulting in empty
output). See stat_referent() for more details. This relies on a sleight of
hand through a new undocumented LayerRef class and associated
ggplot2::ggplot_add() method. As a result, only layers constructed using
this stat_*() shortcut will pass the necessary positional aesthetics to the
$setup_params() step, making them available to pre-process referent data.
The biplot shortcuts automatically substitute the complementary matrix factor
for referent = NULL and will use an integer vector to select a subset from
this factor. These uses do not require the mapping passage.
These are calculated during the statistical transformation and can be accessed with delayed evaluation.
axisunique axis identifier (integer)
lower,upperdistances to endpoints from origin (before offset)
yintercept,xinterceptintercepts (possibly Inf) of offset axis
Gower JC, Gardner–Lubbe S, & le Roux NJ (2011) Understanding Biplots. Wiley, ISBN: 978-0-470-01255-0. https://www.wiley.com/go/biplots
Gower JC & Harding SA (1988) "Nonlinear biplots". Biometrika 75(3): 445–455. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/biomet/75.3.445")}
Other stat layers:
stat_bagplot(),
stat_center(),
stat_chull(),
stat_cone(),
stat_depth(),
stat_scale(),
stat_spantree()
# stack loss gradient
stackloss %>%
lm(formula = stack.loss ~ Air.Flow + Water.Temp + Acid.Conc.) %>%
coef() %>%
as.list() %>% as.data.frame() %>%
subset(select = c(Air.Flow, Water.Temp, Acid.Conc.)) ->
coef_data
# gradient rule with respect to two predictors
stackloss_centered <- scale(stackloss, scale = FALSE)
stackloss_centered %>%
ggplot(aes(x = Acid.Conc., y = Air.Flow)) +
coord_square() +
geom_point(aes(size = stack.loss, alpha = sign(stack.loss))) +
scale_size_area() + scale_alpha_binned(breaks = c(-1, 0, 1)) +
stat_rule(
geom = "axis",
data = coef_data,
referent = stackloss_centered,
fun.offset = function(x) minabspp(x, p = .5)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.