View source: R/geom_ternary_region.R
| geom_ternary_region | R Documentation |
geom_ternary_region() and stat_ternary_region() divide the ternary triangle
into three polygonal regions centered around a specific reference point.
Geometrically, lines are drawn from the reference point perpendicular to the three edges of the triangle. These lines partition the simplex into three zones, where each zone is associated with the closest vertex (item). This is often used to visualize "winning regions" or catchment areas for each item.
geom_ternary_region(
mapping = NULL,
position = "identity",
show.legend = NA,
inherit.aes = FALSE,
x1 = 1/3,
x2 = 1/3,
x3 = 1/3,
vertex_labels = NULL,
...
)
stat_ternary_region(
mapping = NULL,
data = NULL,
geom = "polygon",
position = "identity",
show.legend = NA,
inherit.aes = FALSE,
x1 = 1/3,
x2 = 1/3,
x3 = 1/3,
vertex_labels = NULL,
...
)
StatTernaryRegion
mapping |
Set of aesthetic mappings created by |
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 |
x1, x2, x3 |
Numeric values defining the reference point in ternary coordinates
(proportions). Must sum to 1 (or will be normalized). Default is |
vertex_labels |
Character vector of length 3 providing names for the regions.
The order must correspond to the three vertices of the ternary plot.
If |
... |
Other arguments passed on to
|
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data. Default is |
An object of class StatTernaryRegion (inherits from Stat, ggproto, gg) of length 3.
A ggplot object
stat_ternary_region() calculates the following variables which can be accessed
with after_stat():
x, yCartesian coordinates defining the polygon shapes.
idNumeric identifier for the specific geometric points used to build the polygons:
1-3: The main vertices of the ternary triangle.
4: The reference point (center).
5-7: The projection points on the edges.
groupInteger (1, 2, or 3) identifying which region the polygon belongs to.
vertex_labelsThe label assigned to the region (derived from the
vertex_labels parameter).
library(ggplot2)
# Get ternable
tern22 <- as_ternable(prefviz::aecdop22_transformed, ALP:Other)
# Draw the ternary plot
ggplot(get_tern_data(tern22, plot_type = "2D"), aes(x = x1, y = x2)) +
add_ternary_base() +
geom_ternary_region(
vertex_labels = tern22$vertex_labels,
aes(fill = after_stat(vertex_labels)),
alpha = 0.3, color = "grey50",
show.legend = FALSE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.