Does anyone have any advice, or can point me to a resource, to help with converting a dataframe to a matrix for use in a plot_ly 3d surface graph?
There are a few questions similar to this, but none of them seem to do the trick.
I have a dataframe df
with columns A, B, and C. I’d like to plot A and B on the x-y plane and have C as the z variable.
I can convert my dataframe to a matrix using dfm <- as.matrix(df, rownames.force = NA)
, then I can call plot_ly and reorder columns like so:
fig <- plot_ly(z=~dfm[,c(1,3,2)], type = "surface")
fig <- fig %>% add_surface()
fig
but this gives a very strange result:
which is not at all what the underlying data looks like.
Any advice here? My hunch is the issue is springing from the conversion to a matrix. If so any pointers on how to map a dataframe’s columns onto an x-y-z surface greatly appreciated