Skip to contents

ternary_qap() draws either a static or interactive ternary diagram, in english or spanish. It is a base diagram where data can be plotted.

Usage

ternary_qap(
  output = c("ggplot", "plotly"),
  language = c("en", "es"),
  type = c("plutonic", "volcanic")
)

Arguments

output

The output format: "ggplot" or "plotly" (default is "ggplot")

language

The language to be displayed: "en" for english or "es" for spanish (deafult is "en")

type

The type of volcanic rock: "plutonic" or "volcanic" (default is "plutonic")

Value

QAP ternary diagram for plutonic and volcanic rocks in the desired format (object)

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.

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}'))