ternary_afm()
draws either a static or interactive ternary diagram, in english or spanish. It is a base diagram where data can be plotted.
ternary_afm(output = c("ggplot", "plotly"), language = c("en", "es"))
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") |
AFM ternary diagram in the desired format (object)
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.
library(ggplot2) library(plotly) d = data.frame(f=c(23,26.9,8.5), a=c(27,23.7,5.1), m=c(36,39.8,59.6)) # adding data to ggplot object ternary_afm() + geom_point(data = d)#>#> #> #> #># 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)