2017-09-13 50 views
0

這是一個my previous question隨訪,ggtern + geom_interpolate_tern + expand.formula突發輸出

所以給出的以下數據,

> foo 
Resp   A   B   C 
1 1.629 0.3333333 0.3333333 0.3333333 
2 1.734 0.1666667 0.6666667 0.1666667 
3 1.957 0.0000000 1.0000000 0.0000000 
4 1.778 1.0000000 0.0000000 0.0000000 
5 1.682 0.6666667 0.1666667 0.1666667 
6 1.407 0.1666667 0.1666667 0.6666667 
7 1.589 0.0000000 0.5000000 0.5000000 
8 1.251 0.0000000 0.0000000 1.0000000 
9 1.774 0.5000000 0.5000000 0.0000000 
10 1.940 0.5000000 0.0000000 0.5000000 
> 

我想從this article(私人通道)重現圖。文章稱使用special cubic model

然而,當我嘗試使用符號value ~ (x + y + z)^3 -1,我得到

object 'z' not found 

我以爲是因爲z線性依賴於xy

當我嘗試重新只有xy特殊立方模型,我嘗試使用cubicSquad功能與expand.formula

 > expand.formula(Resp ~ cubicS(A,B) + quad(A,B)) 
     Resp ~ (A + B)^3 + I(A * B * (A - B)) + (A + B)^2 + I(A^2) + I(B^2) 
     > 

但是,geom_interpolate_tern會說我使用了太多的預測,

foo <- 
     structure(
     list(
      Resp = c(1.629, 1.734, 1.957, 1.778, 1.682, 1.407, 
        1.589, 1.251, 1.774, 1.94), 
      A = c(0.3333333, 0.1666667, 0, 1, 
       0.6666667, 0.1666667, 0, 0, 0.5, 0.5), 
      B = c(0.3333333, 0.6666667, 
       1, 0, 0.1666667, 0.1666667, 0.5, 0, 0.5, 0), 
      C = c(0.3333333, 
       0.1666667, 0, 0, 0.1666667, 0.6666667, 0.5, 1, 0, 0.5) 
     ), 
     .Names = c("Resp", 
        "A", "B", "C"), 
     class = "data.frame", 
     row.names = c("1", "2", 
         "3", "4", "5", "6", "7", "8", "9", "10") 
    ) 

    ggtern(data=foo,aes(y = A,x = B,z = C)) + 
     geom_interpolate_tern(
     data = foo, 
     mapping = aes(
      value = Resp,color=..level.. 
     ), 
     formula = expand.formula(value ~ cubicS(x,y) + quad(x,y)), 
     base = "identity" 
    ) 

輸出:

Warning messages: 
     1: In structure(c(), class = c(class(x), class(y))) : 
     Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes. 
    Consider 'structure(list(), *)' instead. 
    2: Computation failed in `stat_interpolate_tern()`: 
     only 1-4 predictors are allowed 
+0

默認黃土時,你需要指定'方法= lm'到插值燕鷗功能。 –

回答

1

默認情況下,插值方法爲'黃土',以保持與ggplot2中默認的平滑方法一致,如geom_smooth(...)。由於黃土退化的預測因子限制,這個錯誤正在被拋出。

無論如何,這很容易修復,請指定method = lm。我已經添加了有色點,以查看模型如何適合您的數據。

ggtern(data=foo,aes(y = A,x = B,z = C)) + 
    geom_point(aes(color=Resp)) + 
    geom_interpolate_tern(
    data = foo, 
    mapping = aes(
     value = Resp,color=..level.. 
    ), 
    method=lm, # <<<<<< SPECIFY METHOD HERE <<<<<<< 
    formula = expand.formula(value ~ cubicS(x,y) + quad(x,y)), 
    base = "identity" 
) 

Output