| Title: | Multiple Geometric Shape Point Layer for 'ggplot2' |
|---|---|
| Description: | To create the multiple polygonal point layer for easily discernible shapes, we developed the package, it is like the 'geom_point' of 'ggplot2'. It can be used to draw the scatter plot. |
| Authors: | Shuangbin Xu [aut, cre] (ORCID: <https://orcid.org/0000-0003-3513-5362>) |
| Maintainer: | Shuangbin Xu <[email protected]> |
| License: | Artistic-2.0 |
| Version: | 1.0.6.990 |
| Built: | 2026-05-20 11:05:06 UTC |
| Source: | https://github.com/xiangpin/ggstar |
Each Geom has an associated function that draws the key when the geom needs to be displayed in a legend. These are the options built into ggplot2.
draw_key_star(data, params, size)draw_key_star(data, params, size)
data |
A single row data frame containing the scaled aesthetics to display in this key |
params |
A list of additional parameters supplied to the geom. |
size |
Width and height of key in mm. |
A grid grob.
geom_star provides the multiple geometric shape to create scatter plot or other point plot, it is like the 'geom_point' of 'ggplot2'. Note: the 'left-triangle' (17, 19) and 'right-triangle' (18, 20) are developed to plot the 'triangle-heatmap'. Their centers are not in their internal, but the center of hypotenuse.
geom_star( mapping = NULL, data = NULL, na.rm = FALSE, stat = "identity", position = "identity", show.legend = NA, inherit.aes = TRUE, ... )geom_star( mapping = NULL, data = NULL, na.rm = FALSE, stat = "identity", position = "identity", 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 |
na.rm |
If 'FALSE', the default, missing values are removed with a warning. If 'TRUE', missing values are silently removed. |
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
|
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
Aesthetics geom_star understands the following aesthetics. Required
aesthetics are displayed in bold and defaults are displayed for optional aesthetics:
x.
y.
starshape the shape of point, default is 1 (star shape).
starstroke control the thickness of margin of point, default is 0.5.
size the size of point, default is 1.5.
colour the colour of margin, default is 'black'.
fill the colour of fill, default is NA.
alpha the transparency of fill, default is 1.
angle control the angle of rotation of point, default is 0.
subset subset the data frame which meet conditions to display.
polygonal point layer
Shuangbin Xu
library(ggplot2) p <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, starshape=Species)) + geom_star(size=4) plibrary(ggplot2) p <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, starshape=Species)) + geom_star(size=4) p
The geometry is based on [geom_star()]. See the documentation for those functions for more details.
geom_star_interactive(...)geom_star_interactive(...)
... |
see also the [geom_star()]. |
library(ggplot2) library(ggiraph) p <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, fill = Species, starshape = Species, tooltip = Species) ) + geom_star_interactive(size=3) girafe(ggobj=p)library(ggplot2) library(ggiraph) p <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, fill = Species, starshape = Species, tooltip = Species) ) + geom_star_interactive(size=3) girafe(ggobj=p)
Create your own discrete scale
scale_starshape_manual(..., values, aesthetic = "starshape") scale_angle_manual(..., values, aesthetic = "angle")scale_starshape_manual(..., values, aesthetic = "starshape") scale_angle_manual(..., values, aesthetic = "angle")
... |
Arguments passed on to
|
values |
a set of aesthetic values to map data values to. If this is a named vector, then the values will be matched based on the names. If unnamed, values will be matched in order (usually alphabetical) with the limits of the scale. Any data values that don't match will be given 'na.value'. |
aesthetic |
The names of the aesthetics that this scale works with. |
starshape scale constructor
‘scale_starshape' maps discrete variables to nine easily discernible shapes (’starshapes'). If you have more than 9 levels, you will get a warning message, and the seventh and subsequence levels will not appear on the plot. Use [scale_starshape_manual()] to supply your own values. You can not map a continuous variable to shape.
scale_starshape(..., default = TRUE)scale_starshape(..., default = TRUE)
... |
Arguments passed on to
|
default |
should the starshapes be default? |
Use values without scaling for ggstar
scale_starshape_identity(..., guide = "none")scale_starshape_identity(..., guide = "none")
... |
Arguments passed on to
|
guide |
Guide to use for this scale. Defaults to '"none"'. |
identical (default) starshape scale constructor
These scales are based on [scale_starshape], [scale_starshape_manual], [scale_starshape_discrete] see the document for those function for more details
scale_starshape_interactive(...) scale_starshape_manual_interactive(...) scale_starshape_discrete_interactive(...)scale_starshape_interactive(...) scale_starshape_manual_interactive(...) scale_starshape_discrete_interactive(...)
... |
arguments passed to base function, plus any of the [interactive_parameters]. |
library(ggplot2) library(ggiraph) iris$id <- seq(nrow(iris)) sps <- as.character(unique(iris$Species)) names(sps) <- sps p <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, fill = Species, starshape = Species, tooltip = Species, data_id = id ) ) + geom_star_interactive(size=2.5, alpha=.8) + scale_starshape_manual_interactive( values = c(1, 12, 15), tooltip = sps, data_id = sps, ) girafe(ggobj=p)library(ggplot2) library(ggiraph) iris$id <- seq(nrow(iris)) sps <- as.character(unique(iris$Species)) names(sps) <- sps p <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, fill = Species, starshape = Species, tooltip = Species, data_id = id ) ) + geom_star_interactive(size=2.5, alpha=.8) + scale_starshape_manual_interactive( values = c(1, 12, 15), tooltip = sps, data_id = sps, ) girafe(ggobj=p)
Show the total star shapes
show_starshapes(...)show_starshapes(...)
... |
see also |
gg object
Shuangbin Xu
p <- show_starshapes() pp <- show_starshapes() p
Construct grid grobs for ggstar star shapes. These functions follow the argument style of [grid::pointsGrob()] and [grid::grid.points()], while using ggstar-specific 'starshape' values. The returned grob can be drawn directly with grid or supplied to custom ggplot2 guides such as 'ggplot2::guide_custom()'.
starGrob( x = 0.5, y = 0.5, starshape = 1, size = unit(2, "mm"), angle = 0, phase = 0, default.units = "npc", name = NULL, gp = gpar(fill = "black", alpha = 1, col = NA, lwd = 0.5), vp = NULL, ... ) grid.star( x = 0.5, y = 0.5, starshape = 1, size = unit(2, "mm"), angle = 0, phase = 0, default.units = "npc", name = NULL, gp = gpar(fill = "black", alpha = 1, col = NA, lwd = 0.5), draw = TRUE, vp = NULL, ... )starGrob( x = 0.5, y = 0.5, starshape = 1, size = unit(2, "mm"), angle = 0, phase = 0, default.units = "npc", name = NULL, gp = gpar(fill = "black", alpha = 1, col = NA, lwd = 0.5), vp = NULL, ... ) grid.star( x = 0.5, y = 0.5, starshape = 1, size = unit(2, "mm"), angle = 0, phase = 0, default.units = "npc", name = NULL, gp = gpar(fill = "black", alpha = 1, col = NA, lwd = 0.5), draw = TRUE, vp = NULL, ... )
x, y
|
Numeric or unit vectors specifying the star positions. |
starshape |
Integer vector of star shape identifiers from 1 to 32. |
size |
Numeric or unit vector giving the star size. Numeric values are interpreted in millimetres. |
angle |
Rotation angle in degrees. |
phase |
Phase shift in radians used when constructing the polygon. |
default.units |
Character string giving the units for 'x' and 'y' when they are numeric. |
name |
A character identifier for the grob. |
gp |
A 'grid::gpar()' object describing graphical parameters. |
vp |
A grid viewport object. |
... |
Additional arguments passed to [grid::polygonGrob()]. Legacy 'position.units' and 'size.units' arguments are still accepted for compatibility. |
draw |
Logical indicating whether to draw the grob. |
'starGrob()' returns a grid grob representing one or more stars. 'grid.star()' draws the grob and invisibly returns it.
[draw_key_star()]
sg <- starGrob( x = 0.5, y = 0.5, starshape = 15, size = grid::unit(8, "mm"), gp = grid::gpar(fill = "gold", col = "grey30") ) grid::grid.newpage() grid::grid.draw(sg)sg <- starGrob( x = 0.5, y = 0.5, starshape = 15, size = grid::unit(8, "mm"), gp = grid::gpar(fill = "gold", col = "grey30") ) grid::grid.newpage() grid::grid.draw(sg)
starshape palette (discrete)
starshape_pal(default = TRUE)starshape_pal(default = TRUE)
default |
should starshapes be reorder (1, 13, 15, 11, 12, 14, 29, 2, 27) or not? |