I am trying to do a 3d surface plot of csv data with R but I don't know how exactly I would do this. The csv File (sphere.csv
) is
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0.447213595,0.565685425,0.6,0.565685425,0.447213595,0,0,0
0,0,0.529150262,0.692820323,0.774596669,0.8,0.774596669,0.692820323,0.529150262,0,0
0,0.447213595,0.692820323,0.824621125,0.894427191,0.916515139,0.894427191,0.824621125,0.692820323,0.447213595,0
0,0.565685425,0.774596669,0.894427191,0.959166305,0.979795897,0.959166305,0.894427191,0.774596669,0.565685425,0
0,0.6,0.8,0.916515139,0.979795897,1,0.979795897,0.916515139,0.8,0.6,0
0,0.565685425,0.774596669,0.894427191,0.959166305,0.979795897,0.959166305,0.894427191,0.774596669,0.565685425,0
0,0.447213595,0.692820323,0.824621125,0.894427191,0.916515139,0.894427191,0.824621125,0.692820323,0.447213595,0
0,0,0.529150262,0.692820323,0.774596669,0.8,0.774596669,0.692820323,0.529150262,0,0
0,0,0,0.447213595,0.565685425,0.6,0.565685425,0.447213595,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
and I was able to read it like so
sphere_data <- read.csv (file="sphere.csv", head=FALSE, sep=",")
Then I tried to to use wireframe
:
library(lattice)
wireframe(z~x+y,sphere_data)
but that gave me an error. Especially, the interpreter seems to choke on the z
of the z~x+y
expression. I don't know what that expression means, but I found it all over in other examples in the internet.
Edit
As per shujaa's suggestion, dput(sphere_data)
returns
structure(list(V1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L), V2 = c(0, 0, 0, 0.447213595, 0.565685425, 0.6, 0.565685425,
0.447213595, 0, 0, 0, 0), V3 = c(0, 0, 0.529150262, 0.692820323,
0.774596669, 0.8, 0.774596669, 0.692820323, 0.529150262, 0, 0,
0), V4 = c(0, 0.447213595, 0.692820323, 0.824621125, 0.894427191,
0.916515139, 0.894427191, 0.824621125, 0.692820323, 0.447213595,
0, 0), V5 = c(0, 0.565685425, 0.774596669, 0.894427191, 0.959166305,
0.979795897, 0.959166305, 0.894427191, 0.774596669, 0.565685425,
0, 0), V6 = c(0, 0.6, 0.8, 0.916515139, 0.979795897, 1, 0.979795897,
0.916515139, 0.8, 0.6, 0, 0), V7 = c(0, 0.565685425, 0.774596669,
0.894427191, 0.959166305, 0.979795897, 0.959166305, 0.894427191,
0.774596669, 0.565685425, 0, 0), V8 = c(0, 0.447213595, 0.692820323,
0.824621125, 0.894427191, 0.916515139, 0.894427191, 0.824621125,
0.692820323, 0.447213595, 0, 0), V9 = c(0, 0, 0.529150262, 0.692820323,
0.774596669, 0.8, 0.774596669, 0.692820323, 0.529150262, 0, 0,
0), V10 = c(0, 0, 0, 0.447213595, 0.565685425, 0.6, 0.565685425,
0.447213595, 0, 0, 0, 0), V11 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L)), .Names = c("V1", "V2", "V3", "V4", "V5",
"V6", "V7", "V8", "V9", "V10", "V11"), class = "data.frame", row.names = c(NA,
-12L))
The data in the csv has 11x11 values. These values are supposed to indicate the height of a point (say z-Axis). All values of the first row in the csv are on the same x axis, and equally so for the values of the second row until the values of the last row. The first values of each row are on the same y axis and equally so for the second values of each row until the values of the last row.