2

I'm trying to duplicate this Minitab ternary plot with ggtern 2.2.1.

Minitab Ternary Contour Plot

My R code is below:

myData<-data.frame(x=c(0.00000, 0.16667, 0.66667, 0.16667, 0.50000, 0.50000, 
                       1.00000, 0.00000, 0.00000, 0.33333),
                   y=c(0.00000, 0.16667, 0.16667, 0.66667, 0.00000, 0.50000, 
                       0.00000, 1.00000, 0.50000, 0.33333),
                   z=c(1.00000, 0.66667, 0.16667, 0.16667, 0.50000, 0.00000, 
                       0.00000, 0.00000, 0.50000, 0.33333),
                   a=c(0.546, 0.550, 0.455, 0.658, 0.451, 0.559, 0.355, 
                       0.762, 0.654, 0.554))

myData$a_breaks<-cut(myData$a, 
                     breaks=seq(0.4, 0.7, 0.1), include.lowest = TRUE)

ggtern(myData, aes(y, x, z))+
  stat_interpolate_tern(aes(value=a, fill=..level..), 
                        geom="polygon",
                        method="lm", 
                        binwidth=0.1, 
                        expand=1, 
                        base="identity")

I've gotten as far as replicating the contour lines (see below), but can't fill them. I also get the message

Warning message:
In structure(c(), class = c(class(x), class(y))) :  
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.

Any guidance as to what I'm doing wrong?

ggtern contour plot

Wissenschaftler
  • 165
  • 1
  • 1
  • 9

1 Answers1

0

By using the answer from this question, I was able to get something approximating what I was looking for, but it's still not quite the same -- for instance, the divisions between the contours look very ragged.

library(ggplot2) 
library(ggtern) 

x<-seq(0,1,0.01)
y<-seq(0,1,0.01)

myData<-expand.grid(x=x,y=y)

myData$z<-1 - (myData$x + myData$y)
myData<-myData[myData$z>(-0.01),]
myData$a<-(0.355*myData$x + 0.762*myData$y + 0.546*myData$z)
myData$a_breaks<-cut(myData$a, breaks=seq(0.3, 0.8, 0.1), include.lowest =         
                     TRUE)

ggtern(myData, aes(y, x, z, color=a_breaks))+
  geom_point(size=5)+
  scale_color_brewer(type="seq", palette = "Blues")

R ternary contour plot

Wissenschaftler
  • 165
  • 1
  • 1
  • 9