I study patterns of whale distribution around specific seabed structures. I am trying to create an interactive 3D graph at the same time:
- bathymetry as a surface (
x
= longitude, y
= latitude, z
= depth) and - geographic location of whale groups (
x
= longitude, y
= latitude, z
= fixed depth of -30 meters, for example).
Coordinates are projected into the UTM coordinate system.
I usually work with R and the ggplot2
package to create shapes. Here the plotly
package looked like a good option.
I started with the bathy_ras
bathymetric raster and the data.frame points
.
> bathy_ras class : RasterLayer dimensions : 784, 821, 643664 (nrow, ncol, ncell) resolution : 102, 111 (x, y) extent : 755070, 838812, -2612148, -2525124 (xmin, xmax, ymin, ymax) coord. ref. : +proj=utm +zone=58S +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 data source : in memory names : bathymetry values : -1949.42, -34.27859 (min, max) > str(points) 'data.frame': 214 obs. of 3 variables: $ x: num 774264 777293 775476 773430 773284 ... $ y: num -2534165 -2533556 -2531012 -2532904 -2533695 ... $ z: num -30 -30 -30 -30 -30 -30 -30 -30 -30 -30 ...
I cannot find a way to combine two datasets on the same graph / same axis. I tried two methods, but none gave me the result I wanted.
1) Creating a graph in Rstudio using a graphics package.
2) Creating a plot entirely on the site. First, I converted the raster "bati_ras" to a matrix containing all coordinate points (x, y) and depth z
#convert raster into a dataframe bathy_df <- as.data.frame(coordinates(bathy_ras)) bathy_df$z <- values(bathy_ras) > str(bathy_df) 'data.frame': 643664 obs. of 3 variables: $ x: num 755121 755223 755325 755427 755529 ... $ y: num -2525179 -2525179 -2525179 -2525179 -2525179 ... $ z: num -362 -361 -360 -359 -358 ...
I created a story account. I imported two data files as .txt files in my graphical account: bathy_df
and points
.
This creates two grids in the graph. I can easily write two separate 3D plots for these two data.frames: one is a surface plot (shown below), the other is a scatter plot. I tried to include the scatterplot in the surface plot as a new trace following this tutorial ( http://help.plot.ly/update-a-graphs-data/ ), but the insert into option is not available if the scatterplot is in 3D surface graphic created from web GUI
Is it possible to combine a scatter3D
and a piece of surface in plotly
?
nb: I tried raster::persp
in combination with points()
, but I am not very satisfied with the general aesthetics of the surface, so I would prefer to do this with plotly
and / or ggplot2
.