Show Sidebar Hide Sidebar

# Ternary Plots in R

How to create ternary plots in R with Plotly.

### New to Plotly?

Plotly's R library is free and open source!
You can set up Plotly to work in online or offline mode.
We also have a quick-reference cheatsheet (new!) to help you get started!

### Version Check

Version 4 of Plotly's R package is now available!
Check out this post for more information on breaking changes and new features available in this version.

``````library(plotly)
packageVersion('plotly')
``````
``````## [1] '4.7.0'
``````

### Basic Ternary Plot with Markers

``````library(plotly)

journalist <- c(75,70,75,5,10,10,20,10,15,10,20)
developer <- c(25,10,20,60,80,90,70,20,5,10,10)
designer <- c(0,20,5,35,10,0,10,70,80,80,70)
label <- c('point 1','point 2','point 3','point 4','point 5','point 6',
'point 7','point 8','point 9','point 10','point 11')

df <- data.frame(journalist,developer,designer,label)

# axis layout
axis <- function(title) {
list(
title = title,
titlefont = list(
size = 20
),
tickfont = list(
size = 15
),
tickcolor = 'rgba(0,0,0,0)',
ticklen = 5
)
}

p <- df %>%
plot_ly() %>%
type = 'scatterternary',
mode = 'markers',
a = ~journalist,
b = ~developer,
c = ~designer,
text = ~label,
marker = list(
symbol = 100,
color = '#DB7365',
size = 14,
line = list('width' = 2)
)
) %>%
layout(
title = "Simple Ternary Plot with Markers",
ternary = list(
sum = 100,
aaxis = axis('Journalist'),
baxis = axis('Developer'),
caxis = axis('Designer')
)
)