I have a compositional set of data investigating sedentary behaviour, sleep and physical activity. Each of these data points is a proportion of time. I want to plot this on a ternary plot using ggtern and have done as follows which results in the below output.
library(ggtern)
library(gtools)
library(zCompositions)
comp_df <- as.data.frame(data[,c("id","PA", "SB", "Sleep")])
ggtern(data = comp_df, aes(Sleep, SB, PA)) +
geom_mask() +
geom_point() +
theme_bw() +
theme_showarrows() +
geom_confidence_tern(colour = "black", breaks = c(0.25, 0.5, 0.75))
Now this is most of the way there. However I want to add a data point that plots the compositional mean of this dataset on the ternary plot, and also labels the co-ordinates of this mean in a specific way. I've use the epicoda package from GitHub to identify the compositional mean and add the appropriate labels as below.
comp_labels <- c("Sleep", "SB", "PA")
library(epicoda)
cm <- comp_mean(comp_df, comp_labels = comp_labels, units = "hr/day")
Then, I can add this easily to my ternary plot with the addition of another geom_point() argument which results in the same output but with the additional point for the compositional mean.
ggtern(data = comp_df, aes(Sleep, SB, PA)) +
geom_mask() +
geom_point() +
geom_point(data = cm) +
theme_bw() +
theme_showarrows() +
geom_confidence_tern(colour = "black", breaks = c(0.25, 0.5, 0.75))
What I want to be able to do is add lines to label the mean with both percentages and time like this image. Any assistance here would be very much appreciated.


Unfortunately you did not provide any data, so this code comes untested, but
geom_[TLR]lineshould help you. For example to mark the mixture20%/20%/60%you could use:That is, something like:
should do the trick.