Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: wireframe like 3D plot for categorical variables

I want to develop wireframe like plot with non-numeric on X, Y axis however numeric in 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 lattice:

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.

like image 682
jon Avatar asked Nov 09 '11 17:11

jon


2 Answers

This appears to work:

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

like image 137
Ben Bolker Avatar answered Nov 17 '22 15:11

Ben Bolker


The easiest way to use the functions in lattice is to use the formula interface.

Assuming that yv is your independent variable:

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

enter image description here

like image 3
Andrie Avatar answered Nov 17 '22 15:11

Andrie