简体   繁体   English

R:用ggtern 2.2.1填充等高线图

[英]R: Filled contour plot with ggtern 2.2.1

I'm trying to duplicate this Minitab ternary plot with ggtern 2.2.1. 我正在尝试使用ggtern 2.2.1复制此Minitab三元图。

Minitab三元轮廓图

My R code is below: 我的R代码如下:

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? 关于我在做什么错的任何指导吗?

图形轮廓图

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")

三元轮廓图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM