R: Filled contour plot with ggtern 2.2.1 -
i'm trying duplicate minitab ternary plot ggtern 2.2.1.
my r code 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 far replicating contour lines (see below), can't fill them. message
warning message: in structure(c(), class = c(class(x), class(y))) : calling 'structure(null, *)' deprecated, null cannot have attributes. consider 'structure(list(), *)' instead. any guidance i'm doing wrong?
by using answer this question, able approximating looking for, it's still not quite same -- instance, divisions between contours 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") 


Comments
Post a Comment