View source: R/geom_starglyph.R
geom_starglyph | R Documentation |
The starglyph geom is used to plot multivariate data as star glyphs \insertCitesiegel_surgical_1972,chambers_graphical_1983,dutoit_graphical_1986gglyph in a scatterplot.
geom_starglyph( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., cols = character(0L), whisker = TRUE, contour = TRUE, colour.whisker = NULL, colour.contour = NULL, colour.points = NULL, linewidth.whisker = 1, linewidth.contour = 1, full = TRUE, draw.grid = FALSE, grid.point.size = 1, legend.glyph.dims = setNames(rep(0.5, length(cols)), cols), show.legend = NA, repel = FALSE, repel.control = gglyph.repel.control(), 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 |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to |
cols |
Name of columns specifying the variables to be plotted in the glyphs as a character vector. |
whisker |
logical. If |
contour |
logical. If |
colour.whisker |
The colour of whiskers. |
colour.contour |
The colour of contours. |
colour.points |
The colour of grid points. |
linewidth.whisker |
The whisker line width. |
linewidth.contour |
The contour line width. |
full |
logical. If |
draw.grid |
logical. If |
grid.point.size |
The size of the grid points in native units. |
legend.glyph.dims |
The dimensions of the legend glyph plot. Can be a numeric vector of unit length (where all the dimensions will have same value) or a numeric vector of same length as "cols" with the "cols" as names. |
show.legend |
logical. Should this layer be included in the legends?
|
repel |
logical. If |
repel.control |
A list of control settings for the repel algorithm.
Ignored if |
inherit.aes |
If |
A geom
layer.
geom_starglyph()
understands the following
aesthetics (required aesthetics are in bold):
x
y
alpha
colour
fill
group
shape
size
stroke
linetype
See vignette("ggplot2-specs", package = "ggplot2")
for further
details on setting these aesthetics.
The following additional aesthetics are considered if repel = TRUE
:
point.size
segment.linetype
segment.colour
segment.size
segment.alpha
segment.curvature
segment.angle
segment.ncp
segment.shape
segment.square
segment.squareShape
segment.inflect
segment.debug
See ggrepel
examples page
for further details on setting these aesthetics.
starglyphGrob
Other geoms:
geom_dotglyph()
,
geom_metroglyph()
,
geom_pieglyph()
,
geom_profileglyph()
,
geom_tileglyph()
# Scale the data zs <- c("hp", "drat", "wt", "qsec", "vs", "am", "gear", "carb") mtcars[ , zs] <- lapply(mtcars[ , zs], scales::rescale) mtcars$cyl <- as.factor(mtcars$cyl) mtcars$lab <- row.names(mtcars) library(ggplot2) theme_set(theme_bw()) options(ggplot2.discrete.colour = RColorBrewer::brewer.pal(8, "Dark2")) options(ggplot2.discrete.fill = RColorBrewer::brewer.pal(8, "Dark2")) # Both whiskers and contour ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp, fill = cyl), cols = zs, whisker = TRUE, contour = TRUE, size = 10, alpha = 0.5) + ylim(c(-0, 550)) ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp, fill = cyl), cols = zs, whisker = TRUE, contour = TRUE, size = 10, alpha = 0.5, full = FALSE) + ylim(c(-0, 550)) ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp, fill = cyl), cols = zs, whisker = TRUE, contour = TRUE, size = 10, alpha = 0.5, linewidth.whisker = 3, linewidth.contour = 0.1) + ylim(c(-0, 550)) ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp, fill = cyl), cols = zs, whisker = TRUE, contour = TRUE, size = 10, alpha = 0.5, linewidth.whisker = 1, linewidth.contour = 3) + ylim(c(-0, 550)) # Only contours (polygon) ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp, fill = cyl), cols = zs, whisker = FALSE, contour = TRUE, size = 10, alpha = 0.5) + ylim(c(-0, 550)) ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp, fill = cyl), cols = zs, whisker = FALSE, contour = TRUE, size = 10, alpha = 0.5, linewidth.contour = 3) + ylim(c(-0, 550)) # Only whiskers ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp, colour = cyl), cols = zs, whisker = TRUE, contour = FALSE, size = 10) + geom_point(data = mtcars, aes(x = mpg, y = disp, colour = cyl)) + ylim(c(-0, 550)) ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp, colour = cyl), cols = zs, whisker = TRUE, contour = FALSE, size = 10, full = FALSE) + geom_point(data = mtcars, aes(x = mpg, y = disp, colour = cyl)) + ylim(c(-0, 550)) # Whiskers with colours ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp), cols = zs, whisker = TRUE, contour = FALSE, size = 10, colour.whisker = RColorBrewer::brewer.pal(8, "Dark2")) + geom_point(data = mtcars, aes(x = mpg, y = disp)) + ylim(c(-0, 550)) # With text annotations ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp, colour = cyl), cols = zs, whisker = TRUE, contour = FALSE, size = 10) + geom_point(data = mtcars, aes(x = mpg, y = disp, colour = cyl)) + geom_text(data = mtcars, aes(x = mpg, y = disp, label = lab), cex = 2) + ylim(c(-0, 550)) # Faceted ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp, fill = cyl), cols = zs, whisker = TRUE, contour = TRUE, size = 10, alpha = 0.5) + ylim(c(-0, 550)) + facet_grid(. ~ cyl) ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp, colour = cyl), cols = zs, whisker = TRUE, contour = TRUE, size = 10) + ylim(c(-0, 550)) + facet_grid(. ~ cyl) # Repel glyphs ggplot(data = mtcars) + geom_point(aes(x = mpg, y = disp, colour = cyl)) + geom_starglyph(aes(x = mpg, y = disp, fill = cyl), cols = zs, whisker = TRUE, contour = TRUE, size = 10, alpha = 1, repel = TRUE) + ylim(c(-0, 550)) + xlim(c(8, 35)) rm(mtcars) mtcars[ , zs] <- lapply(mtcars[ , zs], scales::rescale) mtcars[ , zs] <- lapply(mtcars[, zs], function(x) cut(x, breaks = 3, labels = c(1, 2, 3))) mtcars[ , zs] <- lapply(mtcars[ , zs], as.factor) mtcars$cyl <- as.factor(mtcars$cyl) mtcars$lab <- row.names(mtcars) # Grid points ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp, fill = cyl), cols = zs, whisker = TRUE, contour = TRUE, size = 3, alpha = 0.5, draw.grid = TRUE, grid.point.size = 5) + ylim(c(-0, 550)) ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp, colour = cyl), cols = zs, whisker = TRUE, contour = FALSE, size = 3, draw.grid = TRUE, grid.point.size = 7, linewidth.whisker = 2, alpha = 0.7) + ylim(c(-0, 550)) ggplot(data = mtcars) + geom_starglyph(aes(x = mpg, y = disp), cols = zs, whisker = TRUE, contour = FALSE, size = 3, draw.grid = TRUE, grid.point.size = 5, alpha = 0.8, colour.whisker = RColorBrewer::brewer.pal(8, "Dark2")) + geom_point(data = mtcars, aes(x = mpg, y = disp)) + ylim(c(-0, 550))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.