I want to plot a 3D graph with lattice. I managed to do a 3D scatterplot, but if I try to plot my graph with the wireframe function the graph appears empty.
This is a part of my data with which I could reproduce my issue:
structure(list(z = c(35.6848570203496, 20.6910550942398, 36.2505636561432,
38.9791450251443, 12.9514876234809, 10.0549459964936, 7.1604652315673,
14.681581323841, 29.7104179049907, 8.4814778127832), y = c(21.72,
21.72, 21.72, 21.72, 3.57, 3.57, 4.83, 4.83, 4.83, 4.83), x = c(22L,
136L, 79L, 23L, 34L, 22L, 16L, 66L, 30L, 1L)), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
This is my code:
wireframe(z~x*y,df, scales=list(arrows=FALSE))
Interpolate df
to a regular grid using akima::interp
, remove NA's and then use lattice wireframe
.
library(lattice)
library(akima)
i <- with(df, interp(x, y, z, extrap = TRUE))
g <- with(i, expand.grid(x = x, y = y))
df2 <- data.frame(g, z = c(i$z))
wireframe(z~x*y, na.omit(df2), scales=list(arrows=FALSE))
giving: