I would like to plot the means of a dataset on a ggtern plot.
I found triangle.plot from ade4 library but I would like to do the same using ggtern (it will be easier to modify all the settings). I saw geom_crosshair_tern() but was not able to adapt it.
library(ade4)
data(euro123)
tot <- rbind.data.frame(euro123$in78, euro123$in86, euro123$in97)
row.names(tot) <- paste(row.names(euro123$in78), rep(c(1, 2, 3), rep(12, 3)), sep = "")
triangle.plot(tot, addmean=TRUE,show.position = FALSE)
Here is something to get you started:
library(ggtern)
library(plyr)
df.tot = tot
df.mu = as.data.frame(t(colMeans(tot)))
ggtern(data=df.tot,aes(pri,ter,sec)) +
geom_point() +
geom_crosshair_tern(data=df.mu) +
geom_point(data=df.mu,color='red') +
geom_label(data=100*df.mu,
aes(
y = ter - 5,
label=sprintf("P=%.1f, S=%.1f, T=%.1f",pri,sec,ter)
),
size=3,
color='red'
) +
theme_bw() +
theme_showarrows() +
limit_tern(0.8,0.5,0.7) +
labs(
x = 'Pri',xarrow='Primary',
y = 'Ter',yarrow='Tertiary',
z = 'Sec',zarrow='Secondary'
)