Mixing surface and scatterplot in a single 3D plot

后端 未结 1 575
别跟我提以往
别跟我提以往 2021-02-04 15:33

I am studying the patterns of distribution of whales around specific seabed structures. I am trying to create an interactive 3D plot showing at the same time: <

相关标签:
1条回答
  • 2021-02-04 15:49

    I believe what you are doing should work fine. I think it might have to do with your x and y coordinates. The surface plot is using 1:ncol(bathy_matrix) as the x-axis and 1:row(bathy_matrix) as the y axis points (ticks if you will).

    Your points will need to have x and y coordinates in that range for them to show up in the surface plot. Below is a simple example.

    set.seed(123)
    
    x = sample(1:ncol(volcano), size = 50)
    y = sample(1:nrow(volcano), size = 50)
    
    z = c()
    
    for(i in 1:50) {z <- c(z, volcano[y[i], x[i]])}
    
    df <- data.frame(x, y, z)
    
    plot_ly(z = volcano, type = "surface") %>% 
      add_trace(data = df, x = x, y = y, z = z, mode = "markers", type = "scatter3d", 
                marker = list(size = 5, color = "red", symbol = 104))
    

    I get this:

    Hope this helps...

    0 讨论(0)
提交回复
热议问题