Search code examples
rggplot2data-visualizationdata-analysisggtern

How to add labels on axis in ternary diagram using ggtern package?


The ternary diagram is shown in the following image. I want to add the labels of Z=60, Z=90 and Y=60 using ggtern package in R.

The R code link is the R code of ternary diagram

ternary diagram


Solution

  • This is not the perfect answer, but I tried to achieve your wanted result with annotate like this:

    ggtern(data=DATA,aes(x,y,z)) + 
      geom_polygon(aes(fill=Series),alpha=.5,color="black",size=0.25) +
      scale_fill_manual(values=as.character(unique(DATA$Series))) +
      theme(legend.position=c(0,1),legend.justification=c(0,1)) + 
      labs(fill="Region",title="Sample Filled Regions") +
      annotate(geom  = 'text',
               x     = c(0.1, 1/3, 0.0),
               y     = c(0.0, 0.0, 1.5),
               z     = c(0.5, 1/3, 1.0),
               angle = c(0, 0, 0),
               vjust = c(2.5, 2.5, -1.5),
               hjust = c(0.0, -0.2, 0.0),
               label = c("Z=90","Z=60","Y=60"),
               color = c("black","gray",'orange')) + # for inspection
      theme_nomask()   # allows drawing beyond the borders 
    

    This yields the following picture:

    enter image description here