<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/3-d-shadow-maps-in-r-the-rayshader-package/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2018/09/raytracer.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>Data scientists often work with geographic data that needs to be visualized on a map, and sometimes the maps themselves are the data. The data is often located in two-dimensional space (latitude and longitude), but for some applications we have a third dimension as well: elevation. We could represent the elevations using contours, <a rel="nofollow" href="http://r-nold.blogspot.com/2012/07/colored-3d-map.html" target="_blank">color, or 3-D perspective</a>, but with the new <a rel="nofollow" href="https://github.com/tylermorganwall/rayshader/" target="_blank">rayshader package for R</a> by <a rel="nofollow" href="http://blog.revolutionanalytics.com/2018/09/%20by%20Tyler%20Morgan-Wall" target="_blank">Tyler Morgan-Wall</a>, it's easy to visualize such maps as 3-D relief maps complete with shadows, perspective and depth of field:</p>
<blockquote class="twitter-tweet" data-lang="en">
<p dir="ltr" lang="en"><img alt="👌" src="https://s.w.org/images/core/emoji/2.4/72x72/1f44c.png" class="wp-smiley"> Dead-simple 3D surface plotting in the next version of rayshader! Apply your hillshade (or any image) to a 3D surface map. Video preview with rayshader's built-in palettes. <a rel="nofollow" href="https://twitter.com/hashtag/rstats?src=hash&ref_src=twsrc%5Etfw" target="_blank">#rstats</a></p>
<p>Code:</p>
<p>elmat %>%<br> sphere_shade() %>% <br> add_shadow(ray_shade(elmat)) %>% <br> plot_3d(elmat) <a rel="nofollow" href="https://t.co/FCKQ9OSKpj" target="_blank">pic.twitter.com/FCKQ9OSKpj</a></p>
<p>— Tyler Morgan-Wall (@tylermorganwall) <a rel="nofollow" href="https://twitter.com/tylermorganwall/status/1013760588307095552?ref_src=twsrc%5Etfw" target="_blank">July 2, 2018</a></p></blockquote>
<p></p>
<p>Tyler <a rel="nofollow" href="http://www.tylermw.com/3d-maps-with-rayshader/" target="_blank">describes the rayshader package</a> in a gorgeous blog post: his goal was to generate 3-D representations of landscape data that &quot;looked like a paper weight&quot;. (Incidentally, you can use this package to produce <em>actual</em> paper weights <a rel="nofollow" href="http://www.tylermw.com/3d-printing-rayshader/" target="_blank">with 3-D printing</a>.) To this end, he went beyond simply visualizing a 3-D surface in <code><a rel="nofollow" href="https://www.rdocumentation.org/packages/rgl/versions/0.99.16/topics/rgl-package?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank">rgl</a></code> and added a rectangular &quot;base&quot; to the surface as well as shadows cast by the geographic features. He also added support for detecting (or specifying) a water level: useful for representing lakes or oceans (like the map of the Monterey submarine canyon shown below) and for visualizing the effect of changing water levels like this animation of <a rel="nofollow" href="http://www.tylermw.com/making-beautiful-maps/" target="_blank">draining Lake Mead</a>.</p>
<p><a rel="nofollow" href="http://www.tylermw.com/3d-maps-with-rayshader/" target="_blank"><img border="0" alt="Raytracer" title="Raytracer" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b022ad3b3f5d5200b-800wi"></a></p>
<p>The rayshader package is implemented as an independent R package; it doesn't require any external 3-D graphics software to work. Not only does that make it easy to install and use, but it also means that the underlying computations are available for specialized data analysis tasks. For example, research analyst David Waldran used a LIDAR scan of downtown Indianapolis to create (with the <a rel="nofollow" href="https://cran.r-project.org/web/packages/lidR/index.html" target="_blank">lidR package</a>) a 3-D map of the buildings, and then used the <code><a rel="nofollow" href="https://www.rdocumentation.org/packages/rayshader/versions/0.5.1/topics/ray_shade?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank">ray_shade</a></code> function to simulate the shadows cast by the buildings at various times during a winter's day. Averaging those shadows yields this <a rel="nofollow" href="https://www.waldrn.com/the-shadiest-spots-in-downtown-indianapolis/" target="_blank">map of the shadiest winter spots in Indianapolis</a>:</p>
<p><a rel="nofollow" href="https://www.waldrn.com/the-shadiest-spots-in-downtown-indianapolis/" target="_blank"><img border="0" alt="Indianapolis Winter" title="Indianapolis Winter" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b022ad3945527200d-800wi"></a></p>
<p>The <a rel="nofollow" href="https://mran.microsoft.com/package/rayshader" target="_blank">rayshader package</a> is available for download now from your local CRAN mirror. You can also find an overview, and the latest version of the package at the Github repository linked below.</p>
<p>Github (tylermorganwall): <a rel="nofollow" href="https://github.com/tylermorganwall/rayshader/" target="_blank">rayshader, R Package for Producing and Visualizing Hillshaded Maps from Elevation Matrices, in 2D and 3D</a></p>
<p> </p>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://blog.revolutionanalytics.com/2018/09/raytracer.html"> Revolutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/cbgSDH0V9FI" height="1"></a></div>