R: wireframe as a 3D plot for categorical variables

I want to develop a wireframe that is not numeric on the X, Y axis, but numeric on the Z axis.

# mydata 
set.seed(123)
yv <- rnorm(20, 10, 3)
gen <- rep(paste("G", 1:5, sep= ""), 4)
env <- c(rep(c("CA","MN","SD", "WI"), each = 5))
mdf <- data.frame(yv, gen, env) 

I tried using a grid:

require(lattice)
wireframe(yv,gen, env, data = mdf)

Error in UseMethod("wireframe") : 
  no applicable method for 'wireframe' applied to 
  an object of class "c('double', 'numeric')"

Any suggestions appreciated.

+5
source share
2 answers

It works:

set.seed(123)
mdf <- data.frame(yv=rnorm(20, 10, 3),
                  gen=rep(paste("G", 1:5, sep= ""), 4),
                  env=c(rep(c("CA","MN","SD", "WI"), each = 5)))
library(lattice)
wireframe(yv~gen*env,data=mdf,scales=list(arrows=FALSE))

enter image description here

+5
source

The easiest way to use functions in latticeis to use the formula interface.

Assuming that yvis your independent variable:

wireframe(yv ~ gen + env, data = mdf)

enter image description here

+3
source

All Articles