Skip to contents

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

Usage

ternary_afm(output = c("ggplot", "plotly"), language = c("en", "es"))

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")

Value

AFM ternary diagram 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", "f", and "m", that way it gets mapped automatically, if not make sure to use "aes(x=a,y=f,z=m)". For plotting on the plotly object the mapping of the new data should be as shown in the example: a = ~f, b = ~a, c = ~m, where a refers to the top ("f"), b refers to the bottom left ("a"), and c refers to the bottom right ("m"). The examples show basic usage and how to add data, which can be more customizable.

The AFM diagram is used in igneous petrology to classify volcanic rocks based on their chemical composition, specifically the relative proportions of three major oxides: FeO (F), MgO (M), and Al2O3 (A). The diagram helps to distinguish between tholeiitic and calc-alkaline rock series, which have different magmatic histories and tectonic settings.

Examples

library(ggplot2)
library(plotly)

d = data.frame(f=c(23,40,60),
               a=c(27,50,30),
               m=c(50,10,10))

# adding data to ggplot object
ternary_afm() + geom_point(data = d)
#> Ignoring unknown labels:
#>  T : "F"
#>  L : "A"
#>  R : "M"


# adding data to plotly object
ternary_afm('plotly') %>%
  add_trace(a = ~f, b = ~a, c = ~m,
            data = d,
            name = 'My data',
            type = "scatterternary",
            mode = "markers",
            marker = list(size=8,color='coral',
                          symbol=3,opacity=.9),
            hovertemplate = paste0('F: %{a}<br>',
                                   'A: %{b}<br>',
                                   'M: %{c}')) %>%
  layout(showlegend = TRUE)