繁体   English   中英

如何在 R 中的三元 plot (ggtern) 中指定 model?

[英]How do I specify a model in a ternary plot (ggtern) in R?

我正在尝试使用 packacke ggtern 重现三元 plot
这是一个最小的工作示例(我从 Lawson and Willden (2016) 那里得到这个):

library("mixexp")
library("ggtern")


# ternary plot using ModelPlot (mixexp)
orig <- Xvert(nfac = 3, 
              lc = c(0.35, 0.2, 0.15), 
              uc = c(1, 1, 1),
              ndm = 1, 
              plot = FALSE) 

y <- c(15.3, 20.0, 28.6, 12.5, 32.7, 42.4)
orig <- cbind(orig[1:6, ], y) 
quadm <- lm(y ~ -1 + x1 + x2 + x3 + x1:x2 + x1:x3 + x2:x3, 
            data = orig)

ModelPlot(model = quadm, 
          dimensions = list(x1 = "x1", x2 = "x2", x3 = "x3"),
          lims = c(0.35, 1, 0.20, 1, 0.15, 1),
          constraints = TRUE, 
          contour = TRUE, 
          cuts = 6, 
          fill = F,
          axislabs = c("x1", "x2", "x3"), cornerlabs = c("x1", "x2", "x3"),
          pseudo = T)

现在我想使用ggtern 重现这个 plot 我的想法如下:

# ternary plot using ggtern
my_ternary_plot <- ggtern(data = orig,
                          mapping = aes(x = x1,
                                        y = x2,
                                        z = x3,
                                        value = y)) +
  geom_point() +
  geom_interpolate_tern(method = "lm",
                        formula = value ~ -1 + x + y + z + x:y + x:z + y:z)
my_ternary_plot

但这将在geom_interpolate_tern中返回一条警告消息,因为 z 未知。 那么,从上面接受 model 方程的公式参数的正确语法是什么?

先感谢您!

在三角图中,x、y 和 z 不是 3 个自变量,因为 x+y+z 始终等于 1。我怀疑 ggtern 的第三项有问题。

因此,如果用 I(1-xy) 代替 z,则插值仅根据 2 个自变量。

my_ternary_plot <- ggtern(data = orig,
                          mapping = aes(x = x1,
                                        y = x2,
                                        z = x3,
                                        value = y)) +
   geom_point() +
   geom_interpolate_tern(method = "lm",
                         formula = value ~ -1 + x + y + I(1-x-y) + x:y + x:I(1-x-y) + y:I(1-x-y))
my_ternary_plot

在此处输入图像描述

暂无
暂无

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

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