geom_casting | R Documentation |
Arbitrary hand-crafted colourable and fillable shapes for ggplot2.
New shapes may be feature requested via a Github issue.
geom_casting(
mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...,
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
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
Behind the scenes, a pair of hand-drawn vector images (outline & fill) are converted into Cairo graphics library SVG files, then into grid graphical objects (grobs) for use in a ggplot2 layer.
By default, the "violin" shape is used.
If the shape is mapped to a variable, e.g. aes(shape = factor(cyl))
, then
scale_shape_manual()
is also required to explicitly name the desired
shapes as a character vector (see examples). This is because standard
shapes are associated with a number, e.g. a circle is 19, whereas
geom_casting()
shapes are associated only with character strings.
In addition to the supported aesthetics below, nudge_x
and nudge_y
are
also respected.
A geom layer that can be added to a ggplot.
geom_casting()
understands the following aesthetics (required aesthetics are in bold):
x
y
alpha
angle
colour
fill
group
shape
size
Learn more about setting these aesthetics
in vignette("ggplot2-specs")
library(ggplot2)
# "Baby violin" shape by default
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_casting()
# Change shape & fill
p + geom_casting(shape = "box", fill = "lightgreen")
# Shapes mapped to a variable
ggplot(mtcars, aes(wt, mpg, fill = factor(cyl))) +
geom_casting(aes(shape = factor(cyl))) +
scale_shape_manual(values = c("violin", "dendro", "box"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.