1

This is my first time asking a question here so I apologize in advance if I haven't given enough information. I have the following data frame:

Latitude <- c("-108.6125","-108.5114","-108.805","-108.4014","-108.5615",
              "-108.8349","-108.225","-108.3139","-108.5568","-108.4968")
Longitude <- c("39.02205","39.22255","39.598","38.89478","39.06429",
               "39.27625","39.03","39.1306","39.14823","38.89795")
Depth <- c("60.7735","56.45783","49.65","60.15","50","53.95417",
           "50.825","56","55.843","38.73333")
Salinity <- c("35","34","34.5","36","32","33.5","35","34","35","33")

ctd <- data.frame(x = as.numeric(Latitude), 
                  y = as.numeric(Longitude), 
                  z = as.numeric(Depth), 
                  a = as.numeric(Salinity))

I am trying to produce a 3D plot of the variables Latitude, Longitude, Depth, and an environmental parameter (e.g. Salinity/Temperature etc.) from multiple CTD transects. What I am trying to do looks like this:

CTD transect image

I have tried using plotly with the plot_ly function, which is fairly close to what I want:

plot_ly(x=ctd$x, y=ctd$y, z=ctd$z) %>% add_markers(color = ctd$a)

Plotly image

However, I can't work out how to add interpolated data to plotly. I've previously used mba.surfwhen only wanting to plot Latitude, Depth, and e.g. Salinity but from what I understand mba.surf only accepts 3 variables.

I hope that makes sense. Thanks in advance!

slamballais
  • 3,161
  • 3
  • 18
  • 29
  • Does this post answer your question? https://stackoverflow.com/questions/54726853/how-to-interpolate-data-between-sparse-points-to-make-a-contour-plot-in-r-plot – Andrew Dec 19 '21 at 21:59
  • I will try that out and see whether it looks like I am imagining, thanks!! – DiveDaniela Dec 20 '21 at 21:47
  • @AndrewMorris Thanks again, I think the output of the solution of Cesar is exactly what I want, but I ran into a problem along the way. I made a new post for it as I thought it would exceed the scope of this comment box: https://stackoverflow.com/questions/70442210/r-interp-functions-returns-0s-one-value-for-z-variable – DiveDaniela Dec 22 '21 at 18:46

0 Answers0