Rayshader 1.0: What’s New in R 3D Mapping14 min read2,712 words

Rayshader 1.0: What’s New in R 3D Mapping

Rayshader 1.0 makes 3D mapping in R less manual. See how spatial-aware scenes, water, roads and ggplot2 integration change the workflow—and when it matters.

rayshader 1.03D mapping in RR spatial visualizationrayshader tutorial3D geospatial data
Rayshader 1.0: What’s New in R 3D Mapping

Rayshader 1.0: From Terrain Matrices to Spatial Scenes

Rayshader started as a way to combine cartography and raytracing in R. At first, the promise was pretty simple: take an elevation matrix and turn it into a shaded 3D landscape - without forcing you to move your data into a separate 3D modeling workflow. That worked great for terrain. The moment you wanted roads, buildings, lakes, labels, or other real spatial layers, the workflow got awkward.

The issue wasn't that R couldn't handle those layers. It was that people had to manage too much spatial setup themselves - coordinate systems, extents, scaling, alignment, and the annoying repetition of heightmap information. And that's a real problem when you're on a newsroom deadline, trying to keep an analysis reproducible, or just trying to iterate on a map instead of debugging a coordinate transform.

Rayshader 1.0 addresses this by making scenes spatially aware. It adds a more direct workflow for spatial rasters and vector data, plus new ways to handle water, roads, 3D ggplots, and lighting. This guide walks through what changed, how the spatial-first workflow works, where the new features are actually useful, and where you still need to rely on your data and judgment.

What changed in Rayshader 1.0

The core change is a shift from treating terrain as "just a matrix" to treating a rendered scene as something that can carry spatial context. Rayshader can now keep track of details tied to the input data - its extent and CRS, plus the heightmap and rendering metadata. After that, later functions can reuse that context instead of making you pass the same spatial information over and over.

That changes what a typical workflow looks like. Before 1.0, you might convert a digital elevation model to a matrix, save its extent and CRS separately, transform a road layer to match, and then repeat the same scene setup details each time you add a new layer. With 1.0, the elevation can stay as a spatial raster, and the road layer can stay as a spatial line object. Rayshader uses the scene context to position and filter layers when rendering.

This is both a usability change and a design change. The old API pushed a lot of spatial alignment work onto the user before you even got to the visuals. The new API tries to keep the routine spatial work inside the package, leaving you to make the choices that actually affect the look: color, material, altitude, camera, lighting, and composition.

Less spatial bookkeeping, not less spatial data

Rayshader still has to do the heavy lifting. It converts your data into forms the rendering engine can use, and it still depends on correctly prepared inputs. The difference is that coordinate systems and extents can stay attached to the scene, rather than getting dropped and rebuilt at every step.

This really helps when you're mixing data types. A terrain raster, building polygons, and road lines won't necessarily share the same storage format, and they might not even arrive in the same CRS. When the scene remembers its spatial context, it's easier to combine those layers without turning every addition into a mini GIS preprocessing project.

A broader set of spatial inputs

Rayshader 1.0 lets plot_3d() accept a matrix, a terra::SpatRaster, a raster object, or a raster filename as a heightmap. When you pass spatial raster data, it can pull out information like extent and CRS. If you don't supply zscale, it can also calculate it from the cell resolution.

The release also separates physical scale from visual exaggeration. zscale ties horizontal and vertical units together, while vertical_exaggeration is the stylistic adjustment that makes relief easier to see. Keeping those separate makes the scene easier to reason about: you can preserve a meaningful unit relationship, then exaggerate where it helps readability - without pretending one setting is a replacement for the other.

How does the spatial-first workflow work

Practically, the workflow changes because you can pass spatial data into rendering functions without rebuilding its position inside the scene yourself. A common sequence looks like this: load and prepare a DEM, create a hillshade, build the 3D scene, then add spatial roads, water, or buildings. The functions for those layers handle placement and, when needed, filtering against the scene extent.

Here's the basic flow:

  1. Load a DEM as a spatial raster and prepare its extent and CRS as needed.
  2. Create a visual surface - height_shade() is one example.
  3. Send it to plot_3d() to create the terrain scene.
  4. Add spatial vector layers with functions like render_roads(), render_water(), or render_buildings().
  5. Set the camera and lighting, then render the final image.

The point isn't that every project magically becomes a five-step checklist. Data download, cleaning, and analysis can still be hard. The win is that those steps are less likely to be followed by a second round of manual alignment just to make a line or polygon land correctly on the terrain.

Spatial inputs remain useful after rendering

spatialize_image() is a particularly handy addition. It can take a rayshader image, matrix, or color array and convert it back into a georeferenced terra::SpatRaster, using spatial metadata from the active scene when available. Options can include an alpha channel and the source heightmap as an additional layer.

In other words, it's not strictly a one-way trip. You can style terrain in R and push the result back into a wider GIS workflow, including tools like QGIS or ArcGIS. This matters on teams where R is used for reproducible processing, but GIS software is still where the "real" map output gets produced.

There are trade-offs. A rendered image isn't the same thing as the original vectors or elevation model - it's a visual output with its own resolution and styling choices. If you need to edit features, query values, or keep analytical precision, keep the source data and analysis layers. Export the rendered raster when your goal is a finished visual layer, not a substitute for the underlying dataset.

Where the new workflow saves time

The biggest time savings show up when a scene includes several kinds of data or when you're doing repeated revisions. If your road layer is misaligned, a manual workflow can make it hard to figure out whether the problem is the transform, the extent, the orientation, or the scale. When the scene keeps spatial information, there are fewer moving parts to check.

It also makes iteration less painful. You can spend more time testing camera angles, terrain exaggeration, and lighting, instead of rerunning alignment steps every time someone requests a different crop or you add another layer. This doesn't guarantee fast rendering - high-quality path tracing can still take time. It just makes the setup-and-revise loop easier to manage.

What can you render with the new scene tools

Rayshader 1.0 expands what you can place into a scene from spatial data. Points, lines, and polygons can be passed to the corresponding rendering functions as spatial objects. Building footprints can use height, roof material, and roof angle. Labels can be positioned using spatial features, with polygon inputs converted to centroids when appropriate.

It also addresses a long-standing limitation in water rendering. The older single-level approach is still available as water_render_method = "legacy", and it remains useful for broad coastlines or bathymetry scenes where a single water level works. New methods support water represented by raster cells or polygons, so you can show lakes or reservoirs at different locations and elevations.

The optimized method takes it a step further by searching for a water level that matches a supplied footprint to the terrain. If it can't form a closed water body, it falls back to raster water. That's useful for a lake whose shoreline should follow its basin - but it's still a model built from the terrain and polygon you provide. It can't recover missing bathymetry or fix an inaccurate shoreline on its own.

Streams and terrain-aware water

render_streams() samples elevation along spatial lines and builds water ribbons that follow the terrain. Widths can vary by feature, and connected stream segments can be merged to reduce visible seams in detailed renders. Combined with lake polygons, this supports a hydrology scene where water features are tied to the landscape instead of being drawn as disconnected overlays.

If your DEM doesn't include lake-bed depth, the water surface and terrain may sit on the same plane. The new shift_terrain() function can lower the terrain beneath a water polygon so there's room for the water mesh. That helps prevent overlap, but it's a visual adjustment - worth documenting if readers might mistake it for measured elevation.

Roads need more than a grey line

Roads are a good example of why adding spatial data to a 3D scene isn't just about putting geometry on top of terrain. A grey strip by itself doesn't read as a road without lane markings. And at an interchange, if you draw every crossing as if it's all on the same level, the whole thing gets hard to parse.

Rayshader can use OpenStreetMap lane counts to create road geometry and apply lane markings at an appropriate scale. It can also use road layer ordering to infer which road passes above another. But OSM doesn't provide a complete 3D road design, so layer tags alone can't fully determine bridge height, ramp grades, or how roads connect back to the ground.

The new road workflow treats those details as linked constraints. Its solver can maintain crossing order, enforce a minimum clearance, limit road grades, and keep roads close to the terrain when there's no reason to elevate them. The release describes defaults like 14 feet of clearance and a maximum grade of 7%, and you can change those settings.

That's a more defensible approach than assigning a fixed height to each road layer. One road segment can cross multiple others, and lifting one segment changes the grades needed to reach the next crossing. Still, this is an approximation based on the tags you have and the design constraints you choose, not an engineering-grade road model. Use it to improve visual legibility, not to validate construction plans.

How does Rayshader 1.0 extend ggplot2

Rayshader's plot_gg() has usually worked by turning a ggplot into an extruded surface. That works well for continuous fields, density plots, and other situations where a surface representation makes sense. It's less suitable when you have sharp polygon boundaries, or when marks should float above a flat base rather than become part of the terrain.

Version 1.0 connects plot_gg() more closely to the render_*() functions. The ggplot can supply the coordinate system and the visual foundation, while rayshader adds actual 3D geometry positioned using what the plot defines. For example, for a map of US states, polygon geometry can give each state a clean vertical edge rather than relying on a rasterized image where colors might bleed across boundaries.

Use the plot as a scene coordinate system

With a flat substrate, points and other geometry can sit above a ggplot without being baked into the surface. A 2D plot can give you familiar axes, and the added 3D dimension can represent a third variable. render_zaxis() can provide a readable scale for that height, and facets can be handled panel by panel.

Spatial plots that use coord_sf() can also carry their geographic transform into the scene. That makes it easier to combine familiar ggplot layers with rendered spatial features, including points, paths, and polygons. The benefit isn't just a flashier chart - it's that you can preserve ggplot's layout and scales while adding selected data as real geometry.

There's a cost, though. Adding 3D increases visual complexity, and perspective can make values harder to compare. A raised choropleth or floating point cloud can look compelling while hiding the actual differences. Use the third dimension when it communicates something the 2D version can't show clearly, and keep axes, labels, and camera angles readable. The tool makes more compositions possible; it doesn't make every composition worth making.

When is Rayshader 1.0 the right tool

Rayshader 1.0 is a good match when your story depends on terrain, elevation, spatial relationships, or a carefully composed 3D view. That includes explaining flood extent, showing road crossings at an interchange, visualizing a watershed, or creating a terrain illustration that you'll want to plug back into a GIS workflow.

It's also a strong option when you already work in R and want to combine spatial data with reproducible code. The spatial-first API reduces the amount of glue code between an elevation model and its overlays. New lighting features expand your visual options: haze_shade() can add atmospheric depth, and radiance_shade() can act as a lighting pass you can composite into a faster interactive workflow. For larger geographic areas, setting earth_curvature = TRUE can help communicate global-scale context.

For high-quality renders, a scene that includes spatial metadata can also support time- and location-aware lighting. If you pass a date and time to render_highquality(), rayshader can infer a relevant sun position from the scene. That helps when shadows are part of the explanation - but it doesn't remove the need to choose a viewpoint and verify that the output supports the reading you're aiming for.

When another tool is the better choice

Use a conventional 2D map when readers need quick comparison, precise measurement, or a familiar reference view. Use a GIS application when your main job is editing, querying, or validating spatial features. Use a dedicated 3D modeling workflow when you need detailed assets, animation control, or production features beyond data-driven rendering.

Rayshader isn't a replacement for those tools. Its advantage is that it keeps spatial analysis close to the data and the code that produced it, while still giving you visual rendering. That can improve repeatability and reduce handoffs. But it won't magically clean up messy inputs, and it won't make every render fast. Complex scenes still require sensible geometry, appropriate resolution, and time for lighting and render settings.

Conclusion

Rayshader 1.0 is less about stacking on another set of visual effects and more about removing the friction around getting spatial data into a scene. By keeping spatial context attached to what you're rendering, it reduces the time spent passing extents around and transforming layers - and gives you more time to decide what the visualization should communicate.

If your story depends on 3D terrain or spatial relationships, reach for it. If it doesn't, keep it 2D. The new workflow makes the first option easier to build, but good data, solid assumptions, and a readable composition still do the real work.

Frequently Asked Questions

Rayshader now preserves spatial metadata in a scene, including the coordinate reference system, extent and heightmap. That lets you pass spatial rasters and vector layers into rendering functions without repeatedly converting and aligning them by hand.
No. Rayshader 1.0 can accept spatial rasters such as terra SpatRaster objects, raster objects and raster filenames. Matrix input remains supported, so existing workflows do not have to change immediately.
It can render spatial road, stream and water data with more scene-aware placement. Roads can use lane and layer information to build profiles, while water supports raster, polygon, optimized and legacy methods. The output still depends on the quality of your source data.
No. It is a visualization tool that can now fit more naturally into a GIS workflow. You can prepare spatial data in R or a GIS, render it with rayshader, and export georeferenced imagery for further use.

Related articles