I have latitude, longitude and data value for about 10 locations.
Here's an example of a data frame I can easily construct for my problem
x <- c("-108.6125","-108.5114","-108.805","-108.4014","-108.5615","-108.8349","-108.225","-108.3139","-108.5568","-108.4968")
y <- c("39.02205","39.22255","39.598","38.89478","39.06429","39.27625","39.03","39.1306","39.14823","38.89795")
z <- c("60.7735","56.45783","49.65","60.15","50","53.95417","50.825","56","55.843","38.73333")
df <- data.frame(x = as.numeric(x),y = as.numeric(y),z = as.numeric(z))
I'd like to create a 3d surface based on the x,y, and z values in the data frame. x and y are lat and long. z is the value at the lat, long pair.
I can do a 3d scatter plot with plot_ly(df, x = ~x, y = ~y, z = ~z) %>% add_markers(color = ~z)
but adding add_surface to this code doesn't work.
The plotly 3d surface example involving the volcano df (plot_ly() %>% add_surface(x = ~x, y = ~y, z = ~volcano
) uses evenly spaced x and y values and z is a 2 dimensional array. If I understand correctly, I would need x and y pairs for each location.
Is there some kind of manipulation I can do to create the z matrix needed for the add_surface code?
See Question&Answers more detail:
os