0

I have 3 variables x , y and z. I want to do a surface plot and achieve something like this https://plot.ly/r/3d-surface-plots/

I tried:

library(plotly)
plot_ly(z = xy, type = "surface")

The xy is as below

xy <- read.table(text = "x,y,z
-0.2,-0.4,1
                 -0.116,0.29,0.489
                 -2.416,-1.949,-0.723
                 -0.572,-0.524,-0.331
                 1.71,1.351,0.275
                 -2.708,-0.801,1.357
                 -0.849,0.318,1.256
                 1.1,0.62,-0.179
                 -3.093,-1.344,0.898
                 -1.256,-2.862,-3.193
                 -2.909,-1.745,0.127
                 -0.041,-0.416,-0.646
                 -0.34,-0.273,-0.162
                 1.115,0.442,-0.486
                 0.083,-0.071,-0.279
                 0.322,0.902,1.042
                 -0.515,-0.863,-0.896
                 -4.044,-2.255,0.397
                 -0.865,-0.99,-0.693
                 -0.456,-1.381,-1.794", header = TRUE, sep = ",")

But it wasn't showing the count on the y instead of the variable

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
Keniajin
  • 1,649
  • 2
  • 20
  • 43

1 Answers1

0

This sort of works.

library(plotly)
plot_ly(z = as.matrix(xy) , type = "surface")

enter image description here

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • Thanks...But it shows the row numbers on y instead of the actual value. Is there a way I can change it – Keniajin Jul 01 '16 at 15:52
  • 1
    I have the same problem, where the data in a data frame of three columns x, y, z. How do I reformat the data frame to a matrix which will work with `plot_ly`, i.e. x and y values are transformed to row and column numbers? – M.Teich Oct 10 '18 at 16:50
  • @M.Teich please post a question. Make sure you make a reproducible example. – Roman Luštrik Oct 10 '18 at 17:15
  • @Roman Luštrik I've posted my question here: https://stackoverflow.com/questions/52755652/3d-interactive-surface-plot-with-spatial-data – M.Teich Oct 11 '18 at 08:33