| Title: | High Dimensional Data Visualization |
|---|---|
| Description: | It provides materials (i.e. 'serial axes' objects, Andrew's plot, various glyphs for scatter plot) to visualize high dimensional data. |
| Authors: | Zehao Xu [aut, cre], R. Wayne Oldford [aut], Teun van den Brand [ctb] |
| Maintainer: | Zehao Xu <[email protected]> |
| License: | GPL-2 |
| Version: | 1.0.8 |
| Built: | 2026-06-04 08:51:29 UTC |
| Source: | https://github.com/z267xu/ggmulti |
Project the regular geom layers onto the serial axes coordinate.
add_serialaxes_layers(layer, plot, object, axes)add_serialaxes_layers(layer, plot, object, axes)
layer |
a layer object |
plot |
a |
object |
some parameters used to modify this serial axes |
axes |
canvas sequence axes |
The class is determined by layers you add. For example, you want to add a boxplot layer
on serial axes coordinate.
By the ggplot syntax, it should be ggplot(data, mapping) + geom_boxplot() + coord_serialaxes()
To make it work, object add_serialaxes_layers.GeomBoxplot must be created. In this function,
some computations will be applied.
A radial (spider) coordinate. A wrapper of the function coord_polar() by
forcing it linear.
coord_radial(theta = "x", start = 0, direction = 1, clip = "on")coord_radial(theta = "x", start = 0, direction = 1, clip = "on")
theta |
variable to map angle to ( |
start |
Offset of starting point from 12 o'clock in radians. Offset
is applied clockwise or anticlockwise depending on value of |
direction |
1, clockwise; -1, anticlockwise |
clip |
Should drawing be clipped to the extent of the plot panel? A
setting of |
The serial histogram and serial density cannot be applied on a radial coordinate yet.
if(require("dplyr")) { ggplot(NBAstats2021, mapping = aes(colour = Playoff)) + geom_serialaxes( axes.sequence = c("PTS", "OPTS", "3PM", "O3PM", "PTS"), scaling = "variable" ) + coord_radial() + scale_x_continuous( breaks = 1:5, labels = c("Points", "Oppo Points", "3P Made", "Oppo 3P Made", "Points Per Game")) + scale_y_continuous(labels = NULL) + facet_wrap(~CONF) }if(require("dplyr")) { ggplot(NBAstats2021, mapping = aes(colour = Playoff)) + geom_serialaxes( axes.sequence = c("PTS", "OPTS", "3PM", "O3PM", "PTS"), scaling = "variable" ) + coord_radial() + scale_x_continuous( breaks = 1:5, labels = c("Points", "Oppo Points", "3P Made", "Oppo 3P Made", "Points Per Game")) + scale_y_continuous(labels = NULL) + facet_wrap(~CONF) }
It is mainly used to visualize the high dimensional data set either on the parallel coordinate or the radial coordinate.
coord_serialaxes( axes.layout = c("parallel", "radial"), scaling = c("data", "variable", "observation", "none"), axes.sequence = character(0L), positive = TRUE, ... )coord_serialaxes( axes.layout = c("parallel", "radial"), scaling = c("data", "variable", "observation", "none"), axes.sequence = character(0L), positive = TRUE, ... )
axes.layout |
Serial axes layout, either "parallel" or "radial". |
scaling |
One of |
axes.sequence |
A vector with variable names that defines the axes sequence. |
positive |
If |
... |
other arguments used to modify layers |
Serial axes coordinate system (parallel or radial) is different from the
Cartesian coordinate system or its transformed system (say polar in ggplot2)
since it does not have a formal transformation
(i.e. in polar coordinate system, "x = rcos(theta)", "y = rsin(theta)").
In serial axes coordinate system, mapping aesthetics does not really require "x" or "y". Any "non-aesthetics"
components passed in the mapping system will be treated as an individual axis.
To project a common geom layer on such serialaxes,
users can customize function add_serialaxes_layers.
a ggproto object
In package ggmulti, the function ggplot_build.gg is provided.
At the ggplot construction time, the system will call ggplot_build.gg
first. If the plot input is not a CoordSerialaxes coordinate system, the next method
ggplot_build.ggplot will be called to build a "gg" plot; else
some geometric transformations will be applied first, then the next method
ggplot_build.ggplot will be executed. So, the potential risk is, if some other packages
e.g. foo, also provide a function ggplot_build.gg that is used for their
specifications but the namespace is beyond the ggmulti (ggmulti:::ggplot_build.gg is
covered), error may occur. If so, please consider using the
geom_serialaxes.
if(require("dplyr")) { # Data nba <- NBAstats2021 %>% mutate( dPTS = PTS - OPTS, dREB = REB - OREB, dAST = AST - OAST, dTO = TO - OTO ) # set sequence by `axes.sequence` p <- ggplot(nba, mapping = aes( dPTS = dPTS, dREB = dREB, dAST = dAST, dTO = dTO, colour = Win )) + geom_path(alpha = 0.2) + coord_serialaxes(axes.layout = "radial") + scale_color_gradient(low="blue", high="red") p # quantile layer p + geom_quantiles(quantiles = c(0.5), colour = "green", linewidth = 1.2) # facet p + facet_grid(Playoff ~ CONF) }if(require("dplyr")) { # Data nba <- NBAstats2021 %>% mutate( dPTS = PTS - OPTS, dREB = REB - OREB, dAST = AST - OAST, dTO = TO - OTO ) # set sequence by `axes.sequence` p <- ggplot(nba, mapping = aes( dPTS = dPTS, dREB = dREB, dAST = dAST, dTO = dTO, colour = Win )) + geom_path(alpha = 0.2) + coord_serialaxes(axes.layout = "radial") + scale_color_gradient(low="blue", high="red") p # quantile layer p + geom_quantiles(quantiles = c(0.5), colour = "green", linewidth = 1.2) # facet p + facet_grid(Playoff ~ CONF) }
The dimension of the original data set is n\*p. It can be projected
onto a n\*k space. The functions below are to provide such transformations, e.g.
the Andrews coefficient (a Fourier transformation) and the Legendre polynomials.
andrews(p = 4, k = 50 * (p - 1), ...) legendre(p = 4, k = 50 * (p - 1), ...)andrews(p = 4, k = 50 * (p - 1), ...) legendre(p = 4, k = 50 * (p - 1), ...)
p |
The number of dimensions |
k |
The sequence length |
... |
Other arguments passed on to methods. Mainly used for customized transformation function |
A list contains two named components
vector: A length k vector (define the domain)
matrix: A p\*k transformed coefficient matrix
Andrews, David F. "Plots of high-dimensional data." Biometrics (1972): 125-136.
Abramowitz, Milton, and Irene A. Stegun, eds. "Chapter 8" Handbook of mathematical functions with formulas, graphs, and mathematical tables. Vol. 55. US Government printing office, 1948.
x <- andrews(p = 4) dat <- iris[, -5] proj <- t(as.matrix(dat) %*% x$matrix) matplot(x$vector, proj, type = "l", lty = 1, col = "black", xlab = "x", ylab = "Andrews coefficients", main = "Iris")x <- andrews(p = 4) dat <- iris[, -5] proj <- t(as.matrix(dat) %*% x$matrix) matplot(x$vector, proj, type = "l", lty = 1, col = "black", xlab = "x", ylab = "Andrews coefficients", main = "Iris")
Computes and draws kernel density estimate.
Compared with geom_density(), it provides more general cases that
accepting x and y. See details
geom_density_( mapping = NULL, data = NULL, stat = "density_", position = "identity_", ..., scale.x = NULL, scale.y = c("data", "group", "variable"), as.mix = FALSE, positive = TRUE, prop = 0.9, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_density_( mapping = NULL, data = NULL, geom = "density_", position = "stack_", ..., bw = "nrd0", adjust = 1, kernel = "gaussian", n = 512, trim = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )geom_density_( mapping = NULL, data = NULL, stat = "density_", position = "identity_", ..., scale.x = NULL, scale.y = c("data", "group", "variable"), as.mix = FALSE, positive = TRUE, prop = 0.9, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_density_( mapping = NULL, data = NULL, geom = "density_", position = "stack_", ..., bw = "nrd0", adjust = 1, kernel = "gaussian", n = 512, trim = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
||||||
data |
The data to be displayed in this layer. There are three options: If A 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
|
||||||
scale.x |
A sorted length 2 numerical vector representing the range of the whole data will be scaled to. The default value is (0, 1). |
||||||
scale.y |
one of
If the |
||||||
as.mix |
Logical. Within each group, if |
||||||
positive |
If |
||||||
prop |
adjust the proportional maximum height of the estimate (density, histogram, ...). |
||||||
na.rm |
If |
||||||
orientation |
The orientation of the layer. The default ( |
||||||
show.legend |
logical. Should this layer be included in the legends?
|
||||||
inherit.aes |
If |
||||||
geom, stat
|
Use to override the default connection between
|
||||||
bw |
The smoothing bandwidth to be used.
If numeric, the standard deviation of the smoothing kernel.
If character, a rule to choose the bandwidth, as listed in
|
||||||
adjust |
A multiplicate bandwidth adjustment. This makes it possible
to adjust the bandwidth while still using the a bandwidth estimator.
For example, |
||||||
kernel |
Kernel. See list of available kernels in |
||||||
n |
number of equally spaced points at which the density is to be
estimated, should be a power of two, see |
||||||
trim |
If |
The x (or y) is a group variable (categorical) and y (or x) is the target variable (numerical) to be plotted.
If only one of x or y is provided, it will treated as a target variable and
ggplot2::geom_density will be executed.
There are four combinations of scale.y and as.mix.
scale.y = "group" and as.mix = FALSEThe density estimate area of each subgroup (represented by each color) within the same group is the same.
scale.y = "group" and as.mix = TRUEThe density estimate area of each subgroup (represented by each color) within the same group is proportional to its own counts.
scale.y = "data" and as.mix = FALSEThe sum of density estimate area of all groups is scaled to maximum of 1. and the density area for each group is proportional to the its count. Within each group, the area of each subgroup is the same.
scale.y = "data" and as.mix = TRUEThe sum of density estimate area of all groups is scaled to maximum of 1 and the area of each subgroup (represented by each color) is proportional to its own count.
See vignettes[https://great-northern-diver.github.io/ggmulti/articles/histogram-density-.html] for more intuitive explanation.
This geom treats each axis differently and, thus, can thus have two orientations. Often the orientation is easy to deduce from a combination of the given mappings and the types of positional scales in use. Thus, ggplot2 will by default try to guess which orientation the layer should have. Under rare circumstances, the orientation is ambiguous and guessing may fail. In that case the orientation can be specified directly using the orientation parameter, which can be either "x" or "y". The value gives the axis that the geom should run along, "x" being the default orientation you would expect for the geom.
if(require(dplyr)) { mpg %>% dplyr::filter(drv != "f") %>% ggplot(mapping = aes(x = drv, y = cty, fill = factor(cyl))) + geom_density_(alpha = 0.1) # only `x` or `y` is provided # that would be equivalent to call function `geom_density()` diamonds %>% dplyr::sample_n(500) %>% ggplot(mapping = aes(x = price)) + geom_density_() # density and boxplot # set the density estimate on the left mpg %>% dplyr::filter(drv != "f") %>% ggplot(mapping = aes(x = drv, y = cty, fill = factor(cyl))) + geom_density_(alpha = 0.1, scale.y = "group", as.mix = FALSE, positive = FALSE) + geom_boxplot() # x as density set.seed(12345) suppressWarnings( diamonds %>% dplyr::sample_n(500) %>% ggplot(mapping = aes(x = price, y = cut, fill = color)) + geom_density_(orientation = "x", prop = 0.25, position = "stack_", scale.y = "group") ) } # settings of `scale.y` and `as.mix` ggplots <- lapply(list( list(scale.y = "data", as.mix = TRUE), list(scale.y = "data", as.mix = FALSE), list(scale.y = "group", as.mix = TRUE), list(scale.y = "group", as.mix = FALSE) ), function(vars) { scale.y <- vars[["scale.y"]] as.mix <- vars[["as.mix"]] ggplot(mpg, mapping = aes(x = drv, y = cty, fill = factor(cyl))) + geom_density_(alpha = 0.1, scale.y = scale.y, as.mix = as.mix) + labs(title = paste("scale.y =", scale.y), subtitle = paste("as.mix =", as.mix)) }) suppressWarnings( gridExtra::grid.arrange(grobs = ggplots) )if(require(dplyr)) { mpg %>% dplyr::filter(drv != "f") %>% ggplot(mapping = aes(x = drv, y = cty, fill = factor(cyl))) + geom_density_(alpha = 0.1) # only `x` or `y` is provided # that would be equivalent to call function `geom_density()` diamonds %>% dplyr::sample_n(500) %>% ggplot(mapping = aes(x = price)) + geom_density_() # density and boxplot # set the density estimate on the left mpg %>% dplyr::filter(drv != "f") %>% ggplot(mapping = aes(x = drv, y = cty, fill = factor(cyl))) + geom_density_(alpha = 0.1, scale.y = "group", as.mix = FALSE, positive = FALSE) + geom_boxplot() # x as density set.seed(12345) suppressWarnings( diamonds %>% dplyr::sample_n(500) %>% ggplot(mapping = aes(x = price, y = cut, fill = color)) + geom_density_(orientation = "x", prop = 0.25, position = "stack_", scale.y = "group") ) } # settings of `scale.y` and `as.mix` ggplots <- lapply(list( list(scale.y = "data", as.mix = TRUE), list(scale.y = "data", as.mix = FALSE), list(scale.y = "group", as.mix = TRUE), list(scale.y = "group", as.mix = FALSE) ), function(vars) { scale.y <- vars[["scale.y"]] as.mix <- vars[["as.mix"]] ggplot(mpg, mapping = aes(x = drv, y = cty, fill = factor(cyl))) + geom_density_(alpha = 0.1, scale.y = scale.y, as.mix = as.mix) + labs(title = paste("scale.y =", scale.y), subtitle = paste("as.mix =", as.mix)) }) suppressWarnings( gridExtra::grid.arrange(grobs = ggplots) )
More general histogram (geom_histogram) or bar plot (geom_bar).
Both x and y could be accommodated. See details
geom_hist_( mapping = NULL, data = NULL, stat = "hist_", position = "stack_", ..., scale.x = NULL, scale.y = c("data", "group", "variable"), as.mix = FALSE, binwidth = NULL, bins = NULL, positive = TRUE, prop = 0.9, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) geom_histogram_( mapping = NULL, data = NULL, stat = "bin_", position = "stack_", ..., scale.x = NULL, scale.y = c("data", "group"), as.mix = FALSE, positive = TRUE, prop = 0.9, binwidth = NULL, bins = NULL, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) geom_bar_( mapping = NULL, data = NULL, stat = "count_", position = "stack_", ..., scale.x = NULL, scale.y = c("data", "group"), positive = TRUE, prop = 0.9, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_hist_( mapping = NULL, data = NULL, geom = "bar_", position = "stack_", ..., binwidth = NULL, bins = NULL, center = NULL, boundary = NULL, breaks = NULL, closed = c("right", "left"), pad = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_bin_( mapping = NULL, data = NULL, geom = "bar_", position = "stack_", ..., binwidth = NULL, bins = NULL, center = NULL, boundary = NULL, breaks = NULL, closed = c("right", "left"), pad = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_count_( mapping = NULL, data = NULL, geom = "bar_", position = "stack_", ..., na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )geom_hist_( mapping = NULL, data = NULL, stat = "hist_", position = "stack_", ..., scale.x = NULL, scale.y = c("data", "group", "variable"), as.mix = FALSE, binwidth = NULL, bins = NULL, positive = TRUE, prop = 0.9, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) geom_histogram_( mapping = NULL, data = NULL, stat = "bin_", position = "stack_", ..., scale.x = NULL, scale.y = c("data", "group"), as.mix = FALSE, positive = TRUE, prop = 0.9, binwidth = NULL, bins = NULL, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) geom_bar_( mapping = NULL, data = NULL, stat = "count_", position = "stack_", ..., scale.x = NULL, scale.y = c("data", "group"), positive = TRUE, prop = 0.9, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_hist_( mapping = NULL, data = NULL, geom = "bar_", position = "stack_", ..., binwidth = NULL, bins = NULL, center = NULL, boundary = NULL, breaks = NULL, closed = c("right", "left"), pad = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_bin_( mapping = NULL, data = NULL, geom = "bar_", position = "stack_", ..., binwidth = NULL, bins = NULL, center = NULL, boundary = NULL, breaks = NULL, closed = c("right", "left"), pad = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_count_( mapping = NULL, data = NULL, geom = "bar_", position = "stack_", ..., na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
||||||
data |
The data to be displayed in this layer. There are three options: If A A |
||||||
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function.
Function |
||||||
... |
Other arguments passed on to
|
||||||
scale.x |
A sorted length 2 numerical vector representing the range of the whole data will be scaled to. The default value is (0, 1). |
||||||
scale.y |
one of
If the |
||||||
as.mix |
Logical. Within each group, if |
||||||
binwidth |
The width of the bins. Can be specified as a numeric value
or as a function that takes x after scale transformation as input and
returns a single numeric value. When specifying a function along with a
grouping structure, the function will be called once per group.
The default is to use the number of bins in The bin width of a date variable is the number of days in each time; the bin width of a time variable is the number of seconds. |
||||||
bins |
Number of bins. Overridden by |
||||||
positive |
If |
||||||
prop |
adjust the proportional maximum height of the estimate (density, histogram, ...). |
||||||
na.rm |
If |
||||||
orientation |
The orientation of the layer. The default ( |
||||||
show.legend |
logical. Should this layer be included in the legends?
|
||||||
inherit.aes |
If |
||||||
geom, stat
|
Use to override the default connection between geom_hist_()/geom_histogram_()/geom_bar_() and stat_hist_()/stat_bin_()/stat_count_(). |
||||||
center, boundary
|
bin position specifiers. Only one, |
||||||
breaks |
Alternatively, you can supply a numeric vector giving
the bin boundaries. Overrides |
||||||
closed |
One of |
||||||
pad |
If |
x (or y) is a group variable (categorical) and y (or x) a target variable (numerical) to be plotted.
If only one of x or y is provided, it will treated as a target variable and
ggplot2::geom_histogram will be executed. Several things should be noticed:
1. If both x and y are given, they can be one discrete one continuous or
two discrete. But they cannot be two continuous variables (which one will be considered as a group variable?).
2. geom_hist_ is a wrapper of geom_histogram_ and geom_count_.
Suppose the y is our interest (x is the categorical variable),
geom_hist_() can accommodate either continuous or discrete y. While,
geom_histogram_() only accommodates the continuous y and
geom_bar_() only accommodates the discrete y.
3. There are four combinations of scale.y and as.mix.
scale.y = "group" and as.mix = FALSEThe density estimate area of each subgroup (represented by each color) within the same group is the same.
scale.y = "group" and as.mix = TRUEThe density estimate area of each subgroup (represented by each color) within the same group is proportional to its own counts.
scale.y = "data" and as.mix = FALSEThe sum of density estimate area of all groups is scaled to maximum of 1. and the density area for each group is proportional to the its count. Within each group, the area of each subgroup is the same.
scale.y = "data" and as.mix = TRUEThe sum of density estimate area of all groups is scaled to maximum of 1 and the area of each subgroup (represented by each color) is proportional to its own count.
See vignettes[https://great-northern-diver.github.io/ggmulti/articles/histogram-density-.html] for more intuitive explanation.
Note that, if it is a grouped bar chart (both x and y are categorical),
parameter 'as.mix' is meaningless.
This geom treats each axis differently and, thus, can thus have two orientations. Often the orientation is easy to deduce from a combination of the given mappings and the types of positional scales in use. Thus, ggplot2 will by default try to guess which orientation the layer should have. Under rare circumstances, the orientation is ambiguous and guessing may fail. In that case the orientation can be specified directly using the orientation parameter, which can be either "x" or "y". The value gives the axis that the geom should run along, "x" being the default orientation you would expect for the geom.
if(require(dplyr) && require(tidyr)) { # histogram p0 <- mpg %>% dplyr::filter(manufacturer %in% c("dodge", "ford", "toyota", "volkswagen")) %>% ggplot(mapping = aes(x = manufacturer, y = cty)) p0 + geom_hist_() ## set position #### default is "stack_" p0 + geom_hist_(mapping = aes(fill = fl)) #### "dodge_" p0 + geom_hist_(position = "dodge_", mapping = aes(fill = fl)) #### "dodge2_" p0 + geom_hist_(position = "dodge2_", mapping = aes(fill = fl)) # bar chart mpg %>% ggplot(mapping = aes(x = drv, y = class)) + geom_hist_(orientation = "y") # scale.y as "group" p <- iris %>% tidyr::pivot_longer(cols = -Species, names_to = "Outer sterile whorls", values_to = "x") %>% ggplot(mapping = aes(x = `Outer sterile whorls`, y = x, fill = Species)) + stat_hist_(scale.y = "group", prop = 0.6, alpha = 0.5) p # with density on the left p + stat_density_(scale.y = "group", prop = 0.6, alpha = 0.5, positive = FALSE) ########### only `x` or `y` is provided ########### # that would be equivalent to call function # `geom_histogram()` or `geom_bar()` ### histogram diamonds %>% dplyr::sample_n(500) %>% ggplot(mapping = aes(x = price)) + geom_hist_() ### bar chart diamonds %>% dplyr::sample_n(500) %>% ggplot(mapping = aes(x = cut)) + geom_hist_() }if(require(dplyr) && require(tidyr)) { # histogram p0 <- mpg %>% dplyr::filter(manufacturer %in% c("dodge", "ford", "toyota", "volkswagen")) %>% ggplot(mapping = aes(x = manufacturer, y = cty)) p0 + geom_hist_() ## set position #### default is "stack_" p0 + geom_hist_(mapping = aes(fill = fl)) #### "dodge_" p0 + geom_hist_(position = "dodge_", mapping = aes(fill = fl)) #### "dodge2_" p0 + geom_hist_(position = "dodge2_", mapping = aes(fill = fl)) # bar chart mpg %>% ggplot(mapping = aes(x = drv, y = class)) + geom_hist_(orientation = "y") # scale.y as "group" p <- iris %>% tidyr::pivot_longer(cols = -Species, names_to = "Outer sterile whorls", values_to = "x") %>% ggplot(mapping = aes(x = `Outer sterile whorls`, y = x, fill = Species)) + stat_hist_(scale.y = "group", prop = 0.6, alpha = 0.5) p # with density on the left p + stat_density_(scale.y = "group", prop = 0.6, alpha = 0.5, positive = FALSE) ########### only `x` or `y` is provided ########### # that would be equivalent to call function # `geom_histogram()` or `geom_bar()` ### histogram diamonds %>% dplyr::sample_n(500) %>% ggplot(mapping = aes(x = price)) + geom_hist_() ### bar chart diamonds %>% dplyr::sample_n(500) %>% ggplot(mapping = aes(x = cut)) + geom_hist_() }
Each point glyph can be an image (png, jpeg, etc) object.
geom_image_glyph( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., images, imagewidth = 1.2, imageheight = 0.9, interpolate = TRUE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_image_glyph( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., images, imagewidth = 1.2, imageheight = 0.9, interpolate = TRUE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
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
|
images |
a list of images (a raster object, bitmap image). If not provided, a point visual ( |
imagewidth |
Numerical; width of image |
imageheight |
Numerical; height of image |
interpolate |
A logical value indicating whether to linearly interpolate the image (the alternative is to use nearest-neighbour interpolation,
which gives a more blocky result). See |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
a geom layer
geom_..._glyph() understands the following aesthetics (required aesthetics are in bold):
x
y
alpha
colour
fill
group
size
linetype
shape
stroke
The size unit is cm
Note that the shape and stroke do not have real meanings unless the essential
argument images is missing. If so, a point visual will be displayed with
corresponding shape and stroke.
geom_serialaxes_glyph, geom_polygon_glyph
# image glyph if(require("png")) { img_path <- list.files(file.path(find.package(package = 'ggmulti'), "images"), full.names = TRUE) Raptors <- png::readPNG(img_path[2L]) Warriors <- png::readPNG(img_path[3L]) pg <- ggplot(data = data.frame(x = 1:2, y = rep(1, 2)), mapping = aes(x = x, y = y)) + geom_image_glyph(images = list(Raptors, Warriors), imagewidth = rep(1.2, 2), imageheight = c(0.9, 1.2)) + coord_cartesian(xlim = extendrange(c(1,2))) pg # query the images (a numerical array) build <- ggplot2::ggplot_build(pg) # `imageRaptors` and `imageWarriors` are three dimensional # arrays (third dimension specifying the plane) imageRaptors <- build$data[[1]]$images[[1]] imageWarriors <- build$data[[1]]$images[[2]] if(require("grid")) { grid.newpage() grid.raster(imageRaptors) grid.newpage() grid.raster(imageWarriors) } # THIS IS SLOW mercLogo <- png::readPNG(img_path[1L]) p <- ggplot(mapping = aes(x = hp, y = mpg)) + geom_point( data = mtcars[!grepl("Merc", rownames(mtcars)), ], color = "skyblue") + geom_image_glyph( data = mtcars[grepl("Merc", rownames(mtcars)), ], images = mercLogo, imagewidth = 1.5 ) p }# image glyph if(require("png")) { img_path <- list.files(file.path(find.package(package = 'ggmulti'), "images"), full.names = TRUE) Raptors <- png::readPNG(img_path[2L]) Warriors <- png::readPNG(img_path[3L]) pg <- ggplot(data = data.frame(x = 1:2, y = rep(1, 2)), mapping = aes(x = x, y = y)) + geom_image_glyph(images = list(Raptors, Warriors), imagewidth = rep(1.2, 2), imageheight = c(0.9, 1.2)) + coord_cartesian(xlim = extendrange(c(1,2))) pg # query the images (a numerical array) build <- ggplot2::ggplot_build(pg) # `imageRaptors` and `imageWarriors` are three dimensional # arrays (third dimension specifying the plane) imageRaptors <- build$data[[1]]$images[[1]] imageWarriors <- build$data[[1]]$images[[2]] if(require("grid")) { grid.newpage() grid.raster(imageRaptors) grid.newpage() grid.raster(imageWarriors) } # THIS IS SLOW mercLogo <- png::readPNG(img_path[1L]) p <- ggplot(mapping = aes(x = hp, y = mpg)) + geom_point( data = mtcars[!grepl("Merc", rownames(mtcars)), ], color = "skyblue") + geom_image_glyph( data = mtcars[grepl("Merc", rownames(mtcars)), ], images = mercLogo, imagewidth = 1.5 ) p }
Each point glyph can be a polygon object.
We provide some common polygon coords in polygon_glyph. Also, users can
customize their own polygons.
geom_polygon_glyph( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., polygon_x, polygon_y, linewidth = 1, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_polygon_glyph( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., polygon_x, polygon_y, linewidth = 1, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
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
|
polygon_x |
nested list of x-coordinates of polygons, one list element for each scatterplot point.
If not provided, a point visual ( |
polygon_y |
nested list of y-coordinates of polygons, one list element for each scatterplot point.
If not provided, a point visual ( |
linewidth |
line width of the "glyph" object |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
a geom layer
geom_..._glyph() understands the following aesthetics (required aesthetics are in bold):
x
y
alpha
colour
fill
group
size
linetype
shape
stroke
The size unit is cm
Note that the shape and stroke do not have real meanings unless the essential
argument polygon_x or polygon_y is missing.
If so, a point visual will be displayed with corresponding shape and stroke.
geom_serialaxes_glyph, geom_image_glyph
# polygon glyph p <- ggplot(data = data.frame(x = 1:4, y = 1:4), mapping = aes(x = x, y = y)) + geom_polygon_glyph(polygon_x = list(x_star, x_cross, x_hexagon, x_airplane), polygon_y = list(y_star, y_cross, y_hexagon, y_airplane), colour = 'black', fill = 'red') p # the coords of each polygons can be achieved by calling function `ggplot_build` build <- ggplot2::ggplot_build(p) polygon_x <- build$data[[1]]$polygon_x polygon_y <- build$data[[1]]$polygon_y# polygon glyph p <- ggplot(data = data.frame(x = 1:4, y = 1:4), mapping = aes(x = x, y = y)) + geom_polygon_glyph(polygon_x = list(x_star, x_cross, x_hexagon, x_airplane), polygon_y = list(y_star, y_cross, y_hexagon, y_airplane), colour = 'black', fill = 'red') p # the coords of each polygons can be achieved by calling function `ggplot_build` build <- ggplot2::ggplot_build(p) polygon_x <- build$data[[1]]$polygon_x polygon_y <- build$data[[1]]$polygon_y
In ggplot2, geom_quantile() is used to fit a quantile regression to the data and draws
the fitted quantiles with lines. However, geom_quantiles() is mainly used to draw quantile lines
on serial axes. See examples
geom_quantiles( mapping = NULL, data = NULL, stat = "quantile", position = "identity", ..., lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_quantiles( mapping = NULL, data = NULL, stat = "quantile", position = "identity", ..., lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
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, as a string. |
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
|
lineend |
Line end style (round, butt, square). |
linejoin |
Line join style (round, mitre, bevel). |
linemitre |
Line mitre limit (number greater than 1). |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
p <- ggplot(iris, mapping = aes( Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width, Petal.Length = Petal.Length, Petal.Width = Petal.Width ) ) + geom_path(alpha = 0.2) + coord_serialaxes(scaling = "variable") p + geom_quantiles(colour = c("red", "green", "blue"), quantiles = c(0.25, 0.5, 0.75), linewidth = 2)p <- ggplot(iris, mapping = aes( Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width, Petal.Length = Petal.Length, Petal.Width = Petal.Width ) ) + geom_path(alpha = 0.2) + coord_serialaxes(scaling = "variable") p + geom_quantiles(colour = c("red", "green", "blue"), quantiles = c(0.25, 0.5, 0.75), linewidth = 2)
Draw a serial axes layer, parallel axes under Cartesian system and radial axes under Polar system.
It only takes the "widens" data. Each non-aesthetics component defined in the mapping aes() will
be treated as an axis.
geom_serialaxes( mapping = NULL, data = NULL, stat = "serialaxes", position = "identity", ..., axes.sequence = character(0L), merge = TRUE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_serialaxes( mapping = NULL, data = NULL, geom = "serialaxes", position = "identity", ..., axes.sequence = character(0L), merge = TRUE, axes.position = NULL, scaling = c("data", "variable", "observation", "none"), na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_dotProduct( mapping = NULL, data = NULL, geom = "path", position = "identity", ..., axes.sequence = character(0L), merge = TRUE, scaling = c("data", "variable", "observation", "none"), transform = andrews, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )geom_serialaxes( mapping = NULL, data = NULL, stat = "serialaxes", position = "identity", ..., axes.sequence = character(0L), merge = TRUE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_serialaxes( mapping = NULL, data = NULL, geom = "serialaxes", position = "identity", ..., axes.sequence = character(0L), merge = TRUE, axes.position = NULL, scaling = c("data", "variable", "observation", "none"), na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_dotProduct( mapping = NULL, data = NULL, geom = "path", position = "identity", ..., axes.sequence = character(0L), merge = TRUE, scaling = c("data", "variable", "observation", "none"), transform = andrews, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )
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
|
axes.sequence |
A vector to define the axes sequence. In serial axes coordinate, the sequence can be either
determined in |
merge |
Should |
na.rm |
If |
orientation |
The orientation of the layer. The default ( |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom |
The geometric object to use to display the data for this layer.
When using a
|
axes.position |
A numerical vector to determine the axes sequence position;
the length should be the same with the length of |
scaling |
one of |
transform |
A transformation function, can be either |
The difference between the "lengthens" data and "widens" data can be found in Tidy Data. How to transform one to the other is explained in tidyr
coord_serialaxes, geom_serialaxes_density,
geom_serialaxes_quantile, geom_serialaxes_hist
Andrews plot andrews, Legendre polynomials legendre
# parallel coordinate p <- ggplot(NBAstats2021, mapping = aes(FGA = FGA, `3PA` = `3PA`, FTA = FTA, OFGA = OFGA, O3PA = O3PA, OFTA = OFTA, colour = CONF)) # Teams in West are more likely to make 3-point field goals. # Besides, they have a better performance in restricting opponents # to make 3-point field goals. p + geom_serialaxes(scaling = "variable", alpha = 0.4, linewidth = 3) + scale_x_continuous(breaks = 1:6, labels = c("FGA", "3PA", "FTA", "OFGA", "O3PA", "OFTA")) + scale_y_continuous(labels = NULL) # andrews plot p + geom_serialaxes(stat = "dotProduct", scaling = "variable", transform = andrews) # default # Legendre polynomials p + geom_serialaxes(stat = "dotProduct", scaling = "variable", transform = legendre) ############# Determine axes sequence # 1. set the duplicated axes by mapping aesthetics ggplot(iris, mapping = aes(Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width, Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width, colour = Species)) + # only two axes, duplicated axes are removed geom_serialaxes() # 2. set the duplicated axes by axes.sequence ggplot(iris, mapping = aes(colour = Species)) + geom_serialaxes( axes.sequence = c("Sepal.Length", "Sepal.Width", "Sepal.Length", "Sepal.Width"))# parallel coordinate p <- ggplot(NBAstats2021, mapping = aes(FGA = FGA, `3PA` = `3PA`, FTA = FTA, OFGA = OFGA, O3PA = O3PA, OFTA = OFTA, colour = CONF)) # Teams in West are more likely to make 3-point field goals. # Besides, they have a better performance in restricting opponents # to make 3-point field goals. p + geom_serialaxes(scaling = "variable", alpha = 0.4, linewidth = 3) + scale_x_continuous(breaks = 1:6, labels = c("FGA", "3PA", "FTA", "OFGA", "O3PA", "OFTA")) + scale_y_continuous(labels = NULL) # andrews plot p + geom_serialaxes(stat = "dotProduct", scaling = "variable", transform = andrews) # default # Legendre polynomials p + geom_serialaxes(stat = "dotProduct", scaling = "variable", transform = legendre) ############# Determine axes sequence # 1. set the duplicated axes by mapping aesthetics ggplot(iris, mapping = aes(Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width, Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width, colour = Species)) + # only two axes, duplicated axes are removed geom_serialaxes() # 2. set the duplicated axes by axes.sequence ggplot(iris, mapping = aes(colour = Species)) + geom_serialaxes( axes.sequence = c("Sepal.Length", "Sepal.Width", "Sepal.Length", "Sepal.Width"))
Computes and draws kernel density estimates on serial axes coordinate
for each non-aesthetics component defined in the mapping aes().
geom_serialaxes_density( mapping = NULL, data = NULL, stat = "serialaxes_density", position = "identity_", ..., axes.sequence = character(0L), merge = TRUE, scale.y = c("data", "group"), as.mix = TRUE, positive = TRUE, prop = 0.9, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_serialaxes_density( mapping = NULL, data = NULL, geom = "serialaxes_density", position = "stack_", ..., axes.sequence = character(0L), merge = TRUE, axes.position = NULL, scaling = c("data", "variable", "observation", "none"), bw = "nrd0", adjust = 1, kernel = "gaussian", n = 512, trim = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )geom_serialaxes_density( mapping = NULL, data = NULL, stat = "serialaxes_density", position = "identity_", ..., axes.sequence = character(0L), merge = TRUE, scale.y = c("data", "group"), as.mix = TRUE, positive = TRUE, prop = 0.9, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_serialaxes_density( mapping = NULL, data = NULL, geom = "serialaxes_density", position = "stack_", ..., axes.sequence = character(0L), merge = TRUE, axes.position = NULL, scaling = c("data", "variable", "observation", "none"), bw = "nrd0", adjust = 1, kernel = "gaussian", n = 512, trim = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )
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
|
||||||
axes.sequence |
A vector to define the axes sequence. In serial axes coordinate, the sequence can be either
determined in |
||||||
merge |
Should |
||||||
scale.y |
one of
If the |
||||||
as.mix |
Logical. Within each group, if |
||||||
positive |
If |
||||||
prop |
adjust the proportional maximum height of the estimate (density, histogram, ...). |
||||||
na.rm |
If |
||||||
orientation |
The orientation of the layer. The default ( |
||||||
show.legend |
logical. Should this layer be included in the legends?
|
||||||
inherit.aes |
If |
||||||
geom |
The geometric object to use to display the data for this layer.
When using a
|
||||||
axes.position |
A numerical vector to determine the axes sequence position;
the length should be the same with the length of |
||||||
scaling |
one of |
||||||
bw |
The smoothing bandwidth to be used.
If numeric, the standard deviation of the smoothing kernel.
If character, a rule to choose the bandwidth, as listed in
|
||||||
adjust |
A multiplicate bandwidth adjustment. This makes it possible
to adjust the bandwidth while still using the a bandwidth estimator.
For example, |
||||||
kernel |
Kernel. See list of available kernels in |
||||||
n |
number of equally spaced points at which the density is to be
estimated, should be a power of two, see |
||||||
trim |
If |
geom_density_, geom_serialaxes,
geom_serialaxes_quantile, geom_serialaxes_hist
p <- ggplot(iris, mapping = aes(Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width, Petal.Length = Petal.Length, Petal.Width = Petal.Width, colour = Species, fill = Species)) + geom_serialaxes(alpha = 0.2) + geom_serialaxes_density(alpha = 0.5) + scale_x_continuous(breaks = 1:4, labels = colnames(iris)[-5]) + scale_y_continuous(labels = NULL) + xlab("variable") + ylab("") + theme(axis.text.x = element_text(angle = 45, vjust = 0.5)) pp <- ggplot(iris, mapping = aes(Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width, Petal.Length = Petal.Length, Petal.Width = Petal.Width, colour = Species, fill = Species)) + geom_serialaxes(alpha = 0.2) + geom_serialaxes_density(alpha = 0.5) + scale_x_continuous(breaks = 1:4, labels = colnames(iris)[-5]) + scale_y_continuous(labels = NULL) + xlab("variable") + ylab("") + theme(axis.text.x = element_text(angle = 45, vjust = 0.5)) p
To visualize high dimensional data on scatterplot. Each point glyph is surrounded by a serial axes (parallel axes or radial axes) object.
geom_serialaxes_glyph( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., serialaxes.data, axes.sequence = character(0L), scaling = c("data", "variable", "observation", "none"), axes.layout = c("parallel", "radial"), andrews = FALSE, show.axes = FALSE, show.enclosing = FALSE, linewidth = 1, axescolour = "black", bboxcolour = "black", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_serialaxes_glyph( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., serialaxes.data, axes.sequence = character(0L), scaling = c("data", "variable", "observation", "none"), axes.layout = c("parallel", "radial"), andrews = FALSE, show.axes = FALSE, show.enclosing = FALSE, linewidth = 1, axescolour = "black", bboxcolour = "black", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
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
|
serialaxes.data |
a serial axes numerical data set.
If not provided, a point visual ( |
axes.sequence |
A vector to define the axes sequence. In serial axes coordinate, the sequence can be either
determined in |
scaling |
one of |
axes.layout |
either "radial" or "parallel" |
andrews |
Logical; Andrew's plot (a Fourier transformation) |
show.axes |
boolean to indicate whether axes should be shown or not |
show.enclosing |
boolean to indicate whether enclosing should be shown or not |
linewidth |
line width of the "glyph" object |
axescolour |
axes color |
bboxcolour |
bounding box color |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
a geom layer
geom_..._glyph() understands the following aesthetics (required aesthetics are in bold):
x
y
alpha
colour
fill
group
size
linetype
shape
stroke
The size unit is cm
Note that the shape and stroke do not have real meanings unless the essential
argument serialaxes.data is missing. If so, a point visual will be displayed with
corresponding shape and stroke.
geom_polygon_glyph, geom_image_glyph
# serial axes glyph p <- ggplot(data = iris, mapping = aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) + geom_serialaxes_glyph(serialaxes.data = iris[, -5], axes.layout = "radial") p# serial axes glyph p <- ggplot(data = iris, mapping = aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) + geom_serialaxes_glyph(serialaxes.data = iris[, -5], axes.layout = "radial") p
Computes and draws histogram on serial axes coordinate for each non-aesthetics component
defined in the mapping aes().
geom_serialaxes_hist( mapping = NULL, data = NULL, stat = "serialaxes_hist", position = "stack_", ..., axes.sequence = character(0L), axes.position = NULL, merge = TRUE, scale.y = c("data", "group"), as.mix = TRUE, positive = TRUE, prop = 0.9, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_serialaxes_hist( mapping = NULL, data = NULL, geom = "serialaxes_hist", position = "stack_", ..., axes.sequence = character(0L), scaling = c("data", "variable", "observation", "none"), axes.position = NULL, binwidth = NULL, bins = NULL, center = NULL, boundary = NULL, breaks = NULL, closed = c("right", "left"), pad = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )geom_serialaxes_hist( mapping = NULL, data = NULL, stat = "serialaxes_hist", position = "stack_", ..., axes.sequence = character(0L), axes.position = NULL, merge = TRUE, scale.y = c("data", "group"), as.mix = TRUE, positive = TRUE, prop = 0.9, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_serialaxes_hist( mapping = NULL, data = NULL, geom = "serialaxes_hist", position = "stack_", ..., axes.sequence = character(0L), scaling = c("data", "variable", "observation", "none"), axes.position = NULL, binwidth = NULL, bins = NULL, center = NULL, boundary = NULL, breaks = NULL, closed = c("right", "left"), pad = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )
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
|
||||||
axes.sequence |
A vector to define the axes sequence. In serial axes coordinate, the sequence can be either
determined in |
||||||
axes.position |
A numerical vector to determine the axes sequence position;
the length should be the same with the length of |
||||||
merge |
Should |
||||||
scale.y |
one of
If the |
||||||
as.mix |
Logical. Within each group, if |
||||||
positive |
If |
||||||
prop |
adjust the proportional maximum height of the estimate (density, histogram, ...). |
||||||
na.rm |
If |
||||||
orientation |
The orientation of the layer. The default ( |
||||||
show.legend |
logical. Should this layer be included in the legends?
|
||||||
inherit.aes |
If |
||||||
geom |
The geometric object to use to display the data for this layer.
When using a
|
||||||
scaling |
one of |
||||||
binwidth |
The width of the bins. Can be specified as a numeric value
or as a function that takes x after scale transformation as input and
returns a single numeric value. When specifying a function along with a
grouping structure, the function will be called once per group.
The default is to use the number of bins in The bin width of a date variable is the number of days in each time; the bin width of a time variable is the number of seconds. |
||||||
bins |
Number of bins. Overridden by |
||||||
center, boundary
|
bin position specifiers. Only one, |
||||||
breaks |
Alternatively, you can supply a numeric vector giving
the bin boundaries. Overrides |
||||||
closed |
One of |
||||||
pad |
If |
geom_hist_, geom_serialaxes,
geom_serialaxes_quantile, geom_serialaxes_density
p <- ggplot(NBAstats2021, mapping = aes(`FG%` = `FG%`, `3P%` = `3P%`, `FT%` = `FT%`, `OFG%` = `OFG%`, `O3P%` = `O3P%`, `OFT%` = `OFT%`, colour = Playoff, fill = Playoff)) + geom_serialaxes(alpha = 0.2, scaling = "variable") + geom_serialaxes_hist(alpha = 0.5, prop = 0.7, scaling = "variable") + scale_x_continuous(breaks = 1:6, labels = c("FG", "3P", "FT", "OFG", "O3P", "OFT")) + scale_y_continuous(labels = NULL) + xlab("variable") + ylab("") + theme(axis.text.x = element_text(angle = 45, vjust = 0.5)) pp <- ggplot(NBAstats2021, mapping = aes(`FG%` = `FG%`, `3P%` = `3P%`, `FT%` = `FT%`, `OFG%` = `OFG%`, `O3P%` = `O3P%`, `OFT%` = `OFT%`, colour = Playoff, fill = Playoff)) + geom_serialaxes(alpha = 0.2, scaling = "variable") + geom_serialaxes_hist(alpha = 0.5, prop = 0.7, scaling = "variable") + scale_x_continuous(breaks = 1:6, labels = c("FG", "3P", "FT", "OFG", "O3P", "OFT")) + scale_y_continuous(labels = NULL) + xlab("variable") + ylab("") + theme(axis.text.x = element_text(angle = 45, vjust = 0.5)) p
Draw a quantile layer for serial axes coordinate.
Don't be confused with geom_quantile() which is a quantile regression. See examples.
geom_serialaxes_quantile( mapping = NULL, data = NULL, stat = "serialaxes", position = "identity", ..., quantiles = seq(0, 1, 0.25), axes.sequence = character(0L), merge = TRUE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_serialaxes_quantile( mapping = NULL, data = NULL, geom = "serialaxes_quantile", position = "identity", ..., axes.sequence = character(0L), merge = TRUE, quantiles = seq(0, 1, 0.25), scaling = c("data", "variable", "observation", "none"), axes.position = NULL, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )geom_serialaxes_quantile( mapping = NULL, data = NULL, stat = "serialaxes", position = "identity", ..., quantiles = seq(0, 1, 0.25), axes.sequence = character(0L), merge = TRUE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_serialaxes_quantile( mapping = NULL, data = NULL, geom = "serialaxes_quantile", position = "identity", ..., axes.sequence = character(0L), merge = TRUE, quantiles = seq(0, 1, 0.25), scaling = c("data", "variable", "observation", "none"), axes.position = NULL, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )
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
|
quantiles |
numeric vector of probabilities with values in [0,1]. (Values up to 2e-14 outside that range are accepted and moved to the nearby endpoint.) |
axes.sequence |
A vector to define the axes sequence. In serial axes coordinate, the sequence can be either
determined in |
merge |
Should |
na.rm |
If |
orientation |
The orientation of the layer. The default ( |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom |
The geometric object to use to display the data for this layer.
When using a
|
scaling |
one of |
axes.position |
A numerical vector to determine the axes sequence position;
the length should be the same with the length of |
geom_density_, geom_serialaxes,
geom_serialaxes_density, geom_serialaxes_hist
# lower quantile, median and upper quantile p <- ggplot(iris, mapping = aes(Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width, Petal.Length = Petal.Length, Petal.Width = Petal.Width)) + geom_serialaxes(stat = "dotProduct") + geom_serialaxes_quantile(stat = "dotProduct", quantiles = c(0.25, 0.5, 0.75), colour = c("red", "blue", "green")) p# lower quantile, median and upper quantile p <- ggplot(iris, mapping = aes(Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width, Petal.Length = Petal.Length, Petal.Width = Petal.Width)) + geom_serialaxes(stat = "dotProduct") + geom_serialaxes_quantile(stat = "dotProduct", quantiles = c(0.25, 0.5, 0.75), colour = c("red", "blue", "green")) p
All geom_ functions (like geom_point) return a layer that contains a Geom
object (like GeomPoint). The Geom object is responsible for rendering the data in the plot.
Each of the Geom objects is a ggproto object,
descended from the top-level Geom, and each implements various methods and fields.
Compared to Stat and Position, Geom is a little different
because the execution of the setup and compute functions is split up.
setup_data runs before position adjustments, and draw_layer
is not run until render time, much later. This means there is no setup_params
because it's hard to communicate the changes.
GeomDensity_ GeomBar_ GeomImageGlyph GeomPolygonGlyph GeomQuantiles GeomSerialaxesDensity GeomSerialAxesGlyph GeomSerialaxesHist GeomSerialaxesQuantile GeomSerialaxesGeomDensity_ GeomBar_ GeomImageGlyph GeomPolygonGlyph GeomQuantiles GeomSerialaxesDensity GeomSerialAxesGlyph GeomSerialaxesHist GeomSerialaxesQuantile GeomSerialaxes
An object of class GeomDensity_ (inherits from GeomRibbon, Geom, ggproto, gg) of length 6.
An object of class GeomBar_ (inherits from GeomBar, GeomRect, Geom, ggproto, gg) of length 4.
An object of class GeomImageGlyph (inherits from Geom, ggproto, gg) of length 7.
An object of class GeomPolygonGlyph (inherits from Geom, ggproto, gg) of length 7.
An object of class GeomQuantiles (inherits from GeomQuantile, GeomPath, Geom, ggproto, gg) of length 1.
An object of class GeomSerialaxesDensity (inherits from GeomDensity_, GeomRibbon, Geom, ggproto, gg) of length 2.
An object of class GeomSerialAxesGlyph (inherits from Geom, ggproto, gg) of length 7.
An object of class GeomSerialaxesHist (inherits from GeomBar_, GeomBar, GeomRect, Geom, ggproto, gg) of length 2.
An object of class GeomSerialaxesQuantile (inherits from GeomPath, Geom, ggproto, gg) of length 4.
An object of class GeomSerialaxes (inherits from GeomPath, Geom, ggproto, gg) of length 3.
It is mainly used in serial axes
get_scaledData( data, sequence = NULL, scaling = c("data", "variable", "observation", "none"), displayOrder = NULL, reserve = FALSE, as.data.frame = FALSE )get_scaledData( data, sequence = NULL, scaling = c("data", "variable", "observation", "none"), displayOrder = NULL, reserve = FALSE, as.data.frame = FALSE )
data |
A data frame |
sequence |
vector with variable names that defines the axes sequence.
If |
scaling |
one of |
displayOrder |
the order of the display |
reserve |
If |
as.data.frame |
Return a matrix or a data.frame |
A dataset containing the statistics (e.g. Points Per Game, Average Field Goals Made, etc) of 30 NBA Teams in 2020-2021 regular season
A data frame with 30 rows (teams) and 42 variables:
Team Names.
Factor; Conference of Teams (West or East).
Factor; Division of Teams.
Factor; Whether Teams are in (0 or 1) Playoffs.
Points Per Game.
Average Field Goals Made.
Average Field Goals Attempted.
Field Goal Percentage.
Average 3-Point Field Goals Made.
Average 3-Point Field Goals Attempted.
3-Point Field Goal Percentage.
Average Free Throws Made.
Average Free Throws Attempted.
Free Throw Percentage.
Offensive Rebounds Per Game.
Defensive Rebounds Per Game.
Rebounds Per Game.
Assists Per Game.
Steals Per Game.
Blocks Per Game.
Turnovers Per Game.
Fouls Per Game.
Opponent Points Per Game.
Opponent Average Field Goals Made.
Opponent Average Field Goals Attempted.
Opponent Field Goal Percentage.
Opponent Average 3-Point Field Goals Made.
Opponent Average 3-Point Field Goals Attempted.
Opponent 3-Point Field Goal Percentage.
Opponent Average Free Throws Made.
Opponent Average Free Throws Attempted.
Opponent Free Throw Percentage.
Opponent Offensive Rebounds Per Game.
Opponent Defensive Rebounds Per Game.
Opponent Rebounds Per Game.
Opponent Assists Per Game.
Opponent Steals Per Game.
Opponent Blocks Per Game.
Opponent Turnovers Per Game.
Opponent Fouls Per Game.
Win Games in Regular Season.
Loss Games in Regular Season.
Zehao Xu
https://www.espn.com/nba/stats/team/_/season/2021
polygon coordinates scaled to (0, 1)
x_star y_star x_cross y_cross x_hexagon y_hexagon x_airplane y_airplane x_maple y_maplex_star y_star x_cross y_cross x_hexagon y_hexagon x_airplane y_airplane x_maple y_maple
An object of class numeric of length 10.
An object of class numeric of length 10.
An object of class numeric of length 12.
An object of class numeric of length 12.
An object of class numeric of length 6.
An object of class numeric of length 6.
An object of class numeric of length 32.
An object of class numeric of length 32.
An object of class numeric of length 26.
An object of class numeric of length 26.
if(require("grid")) { library(grid) grid.newpage() grid.polygon(x=(x_star + 1)/2, y=(y_star + 1)/2) grid.newpage() grid.polygon(x=(x_cross + 1)/2, y=(y_cross + 1)/2) grid.newpage() grid.polygon(x=(x_hexagon + 1)/2, y=(y_hexagon + 1)/2) grid.newpage() grid.polygon(x=(x_airplane + 1)/2, y=(y_airplane + 1)/2) grid.newpage() grid.polygon(x=(x_maple + 1)/2, y=(y_maple + 1)/2) }if(require("grid")) { library(grid) grid.newpage() grid.polygon(x=(x_star + 1)/2, y=(y_star + 1)/2) grid.newpage() grid.polygon(x=(x_cross + 1)/2, y=(y_cross + 1)/2) grid.newpage() grid.polygon(x=(x_hexagon + 1)/2, y=(y_hexagon + 1)/2) grid.newpage() grid.polygon(x=(x_airplane + 1)/2, y=(y_airplane + 1)/2) grid.newpage() grid.polygon(x=(x_maple + 1)/2, y=(y_maple + 1)/2) }
Dodging preserves the vertical position of an geom while adjusting the horizontal position.
position_dodge_() dodges bars side by side but conditional on locations.
position_dodge_(width = NULL, preserve = c("total", "single")) position_dodge2_( width = NULL, preserve = c("total", "single"), padding = 0.1, reverse = FALSE )position_dodge_(width = NULL, preserve = c("total", "single")) position_dodge2_( width = NULL, preserve = c("total", "single"), padding = 0.1, reverse = FALSE )
width |
Dodging width, when different to the width of the individual elements. This is useful when you want to align narrow geoms with wider geoms. See the examples. |
preserve |
Should dodging preserve the |
padding |
Padding between elements at the same position. Elements are shrunk by this proportion to allow space between them. Defaults to 0.1. |
reverse |
If |
It is built based on position_dodge, but used for multiple locations, such as
geom_hist_() or geom_density_(). Check examples to see the difference.
position_dodge() understands the following aesthetics. Required aesthetics are displayed in bold and defaults are displayed for optional aesthetics:
| • | order |
→ NULL
|
Learn more about setting these aesthetics in vignette("ggplot2-specs").
position_dodge() understands the following aesthetics. Required aesthetics are displayed in bold and defaults are displayed for optional aesthetics:
| • | order |
→ NULL
|
Learn more about setting these aesthetics in vignette("ggplot2-specs").
See geom_hist_ and geom_serialaxes_hist for more examples.
Other position adjustments for multiple locations:
position_identity_,
position_stack_, position_fill_
Parent: position_dodge
if(require(dplyr)) { p <- iris %>% tidyr::pivot_longer(cols = -Species, names_to = "Outer sterile whorls", values_to = "values") %>% ggplot(data, mapping = aes(x = `Outer sterile whorls`, y = values, fill = Species)) p + geom_hist_(position = position_dodge_()) } # all bins are shifted on the left p + geom_hist_(position = position_dodge())if(require(dplyr)) { p <- iris %>% tidyr::pivot_longer(cols = -Species, names_to = "Outer sterile whorls", values_to = "values") %>% ggplot(data, mapping = aes(x = `Outer sterile whorls`, y = values, fill = Species)) p + geom_hist_(position = position_dodge_()) } # all bins are shifted on the left p + geom_hist_(position = position_dodge())
Don't adjust position
position_identity_()position_identity_()
Other position adjustments for multiple locations:
position_stack_, position_fill_,
position_dodge_, position_dodge2_
position_stack_ stacks bars on top of each other, conditional on locations.
position_stack_(vjust = 1, reverse = FALSE) position_fill_(vjust = 1, reverse = FALSE)position_stack_(vjust = 1, reverse = FALSE) position_fill_(vjust = 1, reverse = FALSE)
vjust |
Vertical adjustment for geoms that have a position
(like points or lines), not a dimension (like bars or areas). Set to
|
reverse |
If |
It is built based on position_stack, but used for multiple locations, such as
geom_hist_ or geom_density_. Rather than stack everything on top of each other,
position_stack_ stacks bars based on locations.
Check examples to see the difference.
See geom_hist_, geom_density_,
geom_serialaxes_density and geom_serialaxes_hist for more examples.
Other position adjustments for multiple locations:
position_identity_,
position_dodge_, position_dodge2_
Parent: position_stack
p <- ggplot(iris, mapping = aes(Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width, Petal.Length = Petal.Length, Petal.Width = Petal.Width, colour = Species)) p + geom_serialaxes_density(position = position_stack_()) p + geom_serialaxes_density(position = position_stack())p <- ggplot(iris, mapping = aes(Sepal.Length = Sepal.Length, Sepal.Width = Sepal.Width, Petal.Length = Petal.Length, Petal.Width = Petal.Width, colour = Species)) p + geom_serialaxes_density(position = position_stack_()) p + geom_serialaxes_density(position = position_stack())
All position_ functions (like position_dodge)
return a Position object (like PositionDodge).
The Position object is responsible for adjusting the position of overlapping geoms.
The way that the position_ functions work is slightly different from the
geom_ and stat_ functions, because a position_ function
actually "instantiates" the Position object by creating a descendant,
and returns that.
Each of the Position objects is a ggproto object,
descended from the top-level Position.
PositionDodge_ PositionDodge2_ PositionIdentity_ PositionStack_ PositionFill_PositionDodge_ PositionDodge2_ PositionIdentity_ PositionStack_ PositionFill_
An object of class PositionDodge_ (inherits from PositionDodge, Position, ggproto, gg) of length 2.
An object of class PositionDodge2_ (inherits from PositionDodge2, PositionDodge, Position, ggproto, gg) of length 2.
An object of class PositionIdentity_ (inherits from PositionIdentity, Position, ggproto, gg) of length 3.
An object of class PositionStack_ (inherits from PositionStack, Position, ggproto, gg) of length 3.
An object of class PositionFill_ (inherits from PositionStack_, PositionStack, Position, ggproto, gg) of length 2.
All stat_ functions (like stat_bin())
return a layer that contains a Stat object (like StatBin).
The Stat object is responsible for rendering the data in the plot.
Each of the Stat objects is a ggproto object,
descended from the top-level Stat, and each implements various methods and fields.
StatDensity_ StatHist_ StatBin_ StatCount_ StatSerialaxesDensity StatSerialaxesHist StatSerialaxes StatDotProductStatDensity_ StatHist_ StatBin_ StatCount_ StatSerialaxesDensity StatSerialaxesHist StatSerialaxes StatDotProduct
An object of class StatDensity_ (inherits from StatDensity, Stat, ggproto, gg) of length 4.
An object of class StatHist_ (inherits from StatBin, Stat, ggproto, gg) of length 4.
An object of class StatBin_ (inherits from StatHist_, StatBin, Stat, ggproto, gg) of length 2.
An object of class StatCount_ (inherits from StatHist_, StatBin, Stat, ggproto, gg) of length 2.
An object of class StatSerialaxesDensity (inherits from StatDensity, Stat, ggproto, gg) of length 4.
An object of class StatSerialaxesHist (inherits from StatBin, Stat, ggproto, gg) of length 4.
An object of class StatSerialaxes (inherits from Stat, ggproto, gg) of length 6.
An object of class StatDotProduct (inherits from StatSerialaxes, Stat, ggproto, gg) of length 4.