geom_huber | R Documentation |
The Huber plot presents the projection pursuit index values of 2D data in each 1D
projection in polar coordinates, corresponding to each projection direction.
It offers a simpler illustration of more complex projection from
high-dimensional data to lower dimensions in projection pursuit. The
function prep_huber()
calculates each component required for the Huber plot
(see details), which can then be supplied to various geom layers in ggplot2.
geom_huber(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
show.legend = NA,
inherit.aes = TRUE
)
prep_huber(data, index)
theme_huber(...)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on 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
|
... |
Other arguments passed on to
|
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
index |
a function, the projection pursuit index function, see examples |
the prep_huber()
function calculates components required for
making the Huber plots. It returns a list including three elements:
idx_df
data frame: the x/y coordinates of the index value, in polar coordinates. Used for plotting the index value at each projection direction, with the reference circle.
proj_df
data frame: the best 1D projection. Used for plotting the 1D projection in histogram.
slope
value: the slope to plot in the Huber plot to indicate the direction of the best 1D projection.
library(ggplot2)
library(tourr)
library(ash)
data(randu)
randu_std <- as.data.frame(apply(randu, 2, function(x) (x-mean(x))/sd(x)))
randu_std$yz <- sqrt(35)/6*randu_std$y-randu_std$z/6
randu_df <- randu_std[c(1,4)]
randu_huber <- prep_huber(randu_df, index = norm_bin(nr = nrow(randu_df)))
ggplot() +
geom_huber(data = randu_huber$idx_df, aes(x = x, y = y)) +
geom_point(data = randu_df, aes(x = x, y = yz)) +
geom_abline(slope = randu_huber$slope, intercept = 0) +
theme_huber() +
coord_fixed()
ggplot(randu_huber$proj_df, aes(x = x)) +
geom_histogram(breaks = seq(-2.2, 2.4, 0.12)) +
xlab("") + ylab("") +
theme_bw() +
theme(axis.text.y = element_blank())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.