ternary_qap() draws either a static or interactive ternary diagram, in english or spanish. It is a base diagram where data can be plotted.
Details
For plotting data on the ggplot object it would be easier if the names of the dataframe are "a", "q", and "p", that way it gets mapped automatically, if not make sure to use "aes(x=a,y=q,z=p)".
For plotting on the plotly object the mapping of the new data should be as shown in the example: a = ~q, b = ~a, c = ~p, where a refers to the top ("q"), b refers to the bottom left ("a"), and c refers to the bottom right ("p").
The examples show basic usage and how to add data, which can be more customizable.
The QAP ternary diagram is used in igneous petrology to classify plutonic and volcanic rocks based on their mineralogical composition, specifically the relative proportions of quartz (Q), alkali feldspar (A), and plagioclase feldspar (P). The diagram helps to infer the petrogenesis and tectonic setting of igneous rocks, as different types of magmatic processes produce characteristic mineral assemblages in the resulting plutonic and volcanic rocks.
See also
Other classification plots, petrology:
TAS(),
ternary_afm(),
ternary_dickinson_qmflt(),
ternary_dickinson_qtfl(),
ternary_fap(),
ternary_feldspars(),
ternary_folk_gsm(),
ternary_folk_qfl(),
ternary_folk_qfm(),
ternary_folk_smc(),
ternary_pyroclastic_size(),
ternary_pyroclastic_type(),
ternary_qap_g(),
ternary_qap_m_hbl(),
ternary_qap_m_ol(),
ternary_qap_um(),
ternary_qap_um_hbl()
Examples
library(ggplot2)
library(plotly)
d = data.frame(q=c(23,40,60),
a=c(27,50,30),
p=c(50,10,10))
# adding data to ggplot object
ternary_qap() + geom_point(data = d)
#> Warning: Removing Layer 2 ('PositionNudge'), as it is not an approved position (for ternary plots) under the present ggtern package.
#> Ignoring unknown labels:
#> • T : "Q"
#> • L : "A"
#> • R : "P"
# adding data to plotly object
ternary_qap('plotly') %>%
add_trace(a = ~q, b = ~a, c = ~p,
data = d,
name = 'My data',
type = "scatterternary",
mode = "markers",
marker = list(size=8,color='coral',
symbol=3,opacity=.9),
hovertemplate = paste0('Q: %{a}<br>',
'A: %{b}<br>',
'P: %{c}'))