r - ggtern + geom_interpolate_tern + expand.formula with unexpected output -
this followup my previous question,
so given following data,
> foo resp 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 >
i trying reproduce chart this article (private access). article claims use special cubic model
however, when try use notation value ~ (x + y + z)^3 -1
, get
object 'z' not found
which assume because z
linearly dependent on x
, y
.
when try recreate special cubic model x
, y
, tried using cubics
, quad
functions 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) >
however, geom_interpolate_tern
using many predictors,
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), = 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" )
output:
warning messages: 1: in structure(c(), class = c(class(x), class(y))) : calling 'structure(null, *)' deprecated, null cannot have attributes. consider 'structure(list(), *)' instead. 2: computation failed in `stat_interpolate_tern()`: 1-4 predictors allowed
by default, interpolation method 'loess', maintain consistent default smoothing method in ggplot2
things geom_smooth(...)
. error being thrown, due predictors limit loess regression.
no matter, fixed, specify method = lm
instead. have added coloured points see how model fits respect data.
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" )
Comments
Post a Comment