dem <- raster::raster('C:/Users/MIRKO DELFIN/Google Drive/R_STUDIO/2_TOPOGRAFIA/dem.tif')

#And convert it to a matrix:
elmat = raster_to_matrix(dem)

volc <- reshape2::melt(elmat)  

with(volc, scatter3D(x = Var1, y = Var2, z = value,aspect = c(1000, 1000, 100), ticktype="detailed", pch=16, 
                     xlab="x", ylab="y", zlab="Altitud, m", main=""))

plotrgl(lighting = TRUE, smooth = TRUE, cex=2)

You must enable Javascript to view this page properly.

sessionInfo()
## R version 3.5.0 (2018-04-23)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18362)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=English_United States.1252 
## [2] LC_CTYPE=English_United States.1252   
## [3] LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C                          
## [5] LC_TIME=English_United States.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] plot3Drgl_1.0.1  plot3D_1.1.1     rgl_0.99.16      reshape2_1.4.3  
##  [5] rgdal_1.3-6      sp_1.3-1         plotly_4.8.0     ggplot2_3.0.0   
##  [9] rayshader_0.13.1 knitr_1.26      
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.3             lattice_0.20-35        tidyr_1.0.0           
##  [4] prettyunits_1.0.2      png_0.1-7              assertthat_0.2.1      
##  [7] zeallot_0.1.0          digest_0.6.15          foreach_1.4.7         
## [10] mime_0.5               R6_2.4.0               imager_0.41.2         
## [13] tiff_0.1-5             plyr_1.8.4             backports_1.1.2       
## [16] evaluate_0.14          httr_1.3.1             pillar_1.4.0          
## [19] rlang_0.4.0            progress_1.2.0         misc3d_0.8-4          
## [22] lazyeval_0.2.1         data.table_1.12.2      miniUI_0.1.1.1        
## [25] raster_2.8-4           bmp_0.3                rmarkdown_1.18        
## [28] stringr_1.3.0          htmlwidgets_1.3        igraph_1.2.4.1        
## [31] munsell_0.5.0          shiny_1.3.2            compiler_3.5.0        
## [34] httpuv_1.5.1           xfun_0.11              pkgconfig_2.0.2       
## [37] htmltools_0.3.6        readbitmap_0.1.5       tidyselect_0.2.5      
## [40] tibble_2.1.1           rayrender_0.4.2        codetools_0.2-15      
## [43] viridisLite_0.3.0      crayon_1.3.4           dplyr_0.8.3           
## [46] withr_2.1.2            later_0.8.0            grid_3.5.0            
## [49] jsonlite_1.6           xtable_1.8-2           gtable_0.2.0          
## [52] lifecycle_0.1.0        magrittr_1.5           scales_1.0.0          
## [55] stringi_1.1.7          promises_1.0.1         doParallel_1.0.15     
## [58] vctrs_0.2.0            iterators_1.0.10       tools_3.5.0           
## [61] manipulateWidget_0.9.0 glue_1.3.1             markdown_0.8          
## [64] purrr_0.2.5            hms_0.4.2              crosstalk_1.0.0       
## [67] jpeg_0.1-8             parallel_3.5.0         yaml_2.1.19           
## [70] colorspace_1.3-2