User Request – Middle Segments
Recently, a user of ggtern was desirable to produce a plot similar to what can be found HERE. This is relatively simple, given the use of layers during plot construction.
In ggplot2 (and hence ggtern), one can define a 'global' dataframe in the constructor, which gets picked up by each layer, UNLESS one states an alternate data-source on a per-layer basis, therefore, we can use one data set for the points, and, another specifically for the red segments meeting at the middle.
#Load the ggtern library library(ggtern) #Create Some Random (Trivial) Data and ensure the rows sum to unity random <- data.frame(T = runif(100), L = runif(100), R = runif(100)) random <- random/apply(random, 1, sum) # For Rendering the Lines, use Segment geometry lines <- data.frame(x = c(0.5, 0, 0.5), y = c(0.5, 0.5, 0), z = c(0, 0.5, 0.5), xend = c(1, 1, 1)/3, yend = c(1, 1, 1)/3, zend = c(1, 1, 1)/3) # Render. ggtern(data = random, aes(T, L, R)) + geom_point() + geom_segment(data = lines, aes(x, y, z, xend = xend, yend = yend, zend = zend), color = 'red', size = 1)






Comments
> Error in ggint$map_layout(panel, plot$facet, layer_data, plot$data) : unused argument (plot$data)
Marianoju, I have just submitted a new version to CRAN which resolves this error.
Hi Nick,
Thanks for the example. Is there a way to extract points from each part of the polygon ?
Thanks,