/rayshader_portraits

Primary LanguageRGNU General Public License v3.0GPL-3.0

About

This repo houses code I use to create shaded relief graphics using the rayshader R package by Tyler Morgan-Wall. I'm walking in the giant steps of Twitter user flotsam whose graphics originally inspired me, and tips + code snippets they shared helped immensely as I was just learning how to make these.

I've been making these graphics for a while (see my gallery) and wanted to share code from the start, but I was self-conscious about the state of my code. This repo is an effort to better organize my code so I can be confident in sharing it.

Repo Structure

Code to create each graphic has its own directory within the R/portraits directory, and helper functions can be found in the R/utils directory.

Graphics are written to an images directory, but I'm not tracking it here because the graphics tend to be pretty large files. Instead, I copy the smaller version of the graphics (created for posting to platforms like Instagram or Reddit where file size limits are enforced) to the tracked_graphics directory so there is something to showcase here.

Workflow

Here's a sample workflow you could use to repurpose this code for your own geography (assuming you've forked or otherwise copied this directory):

  1. Call .new_portrait() to start work on a portrait. This function takes one argument, which is the name of the map.
    • If it is based on a US National Park, the name will be used to filter the master list of park geometries for the one you specified in the function call.
    • This function will create a new directory within R/portraits, with the directory name determined by map argument in the the function call.
    • .new_portrait() is loaded whenever you open the project via the .Rprofile file, but it remains hidden from the environment because its name begins with a leading period.
  2. Run the code in the render_graphic.R file, an example of which is R/portraits/bryce_canyon/render_graphic.R.
    • If you're changing things up at all, this will be an iterative process.
    • Start with a lower z value so you're working with less data, and it's easier to iterate as you work to to get everything set how you want it.
    • When you're ready to render the final graphic, bump it up to the highest resolution you want.
  3. Run the code in markup.R (e.g. R/portraits/bryce_canyon/markup.R), adjusting the code as necessary for your given scenario.
    • The code is structured to allow for aligning text, but currently I have only built it out to allow for center aligned. Aligning to left or right will involve handling those settings by setting {magick}'s gravity argument to 'west' or 'east', and then adjusting the coords accordingly. You could achieve this directly with {magick} as well if you want more direct control.
    • I'm making improvements to the utils functions as I go, so earlier render and markup scripts might need updating to work with new functions. I am not maintaining backwards compatibility.
  4. The code as I've written it will save two files, one at a higher resolution, and one at a lower resolution that should fall under the limits for sites like Instagram and Reddit.

Graphics

Washington Population Density

Mediterranean Coast Population Density

Illinois Population Density

Kansas Population Density

Amazon River Population Density

Virginia Population Density

Pennsylvania Population Density

Ohio Population Density

Georgia Population Density

The Nile Population Density

North Carolina Population Density

Minnesota Population Density

Colorado River Population Density

Michigan Population Density

Death Valley

Pillars of Creation

Pillars of Creation

Pillars of Creation

Pillars of Creation

Pillars of Creation

Pillars of Creation

Mount Katmai

Katmai National Park

Kobuk Valley National Park

Voyageurs National Park

Voyageurs National Park

Voyageurs National Park

Washington National Parks

North Cascades National Park

Mount Rainier National Park

Olympic National Park

Congaree National Park

Badlands National Park

Mighty Five National Parks of Utah

Bryce Canyon National Park

Zion National Park

Arches National Park

Canyonlands National Park

Capitol Reef National Park

Crater of Vélingara

Eye of the Sahara

Great Basin

San Andreas Fault at Temblor Range

Glacier National Park

Glacier National Park

Kings Canyon National Park

Interstate 70

Sequoia National Park

Great Smoky Mountains

Bryce Canyon