Regional Climate Narratives

Marc Los Huertos

EA030 · Compiled 2026-08-17

Download Install Get Data Analysis Heat Maps Results Reference Troubleshooting

🎯 Learning Outcomes

  1. Install an R source package (tar.gz) and its dependencies on RStudio Server.
  2. Download and manage a multi-decade NOAA GHCN daily weather dataset for an assigned state.
  3. Explain climate normals, anomalies, and trends, and how a baseline period shapes each.
  4. Compute per-station temperature and precipitation trends with process_all_stations().
  5. Create interpolated heat maps of annual and seasonal trends with create_heatmap().
  6. Interpret spatial and seasonal patterns of climate change to support a climate narrative.

What this activity covers. Every weather station tells a hundred-year story, but a single thermometer cannot show where and when a state is changing fastest. In this activity you will install the Regional Climate Narratives package, RegionalClimateNarratives (v0.3.1), download daily records for your assigned state’s 50 longest-running NOAA stations, convert raw observations into normals, anomalies, and century-scale trends, and map those trends across your state. The maps become the evidence base for your climate narrative video.

Part 1 · once ever
Install
Upload the zip, install dependencies and the package.
Part 2 · once per state
Get Data
Select 50 stations and download their NOAA records.
Part 3 · every session
Analyze
Reload data, compute trends, build spatial objects.
Part 3 · deliverable
Map
Make annual and seasonal heat maps for your narrative.

Download the Course Files

📦 Download first: Regional_Climate_Narratives–Student_Files.zip (0 MB) The zip contains everything you need to upload to the RStudio Server:

Save the zip somewhere you can find it (Downloads is fine). In Part 1 you will create a regional_climate_narratives folder on the server and upload the zip there.

You also need:


Part 1: Install the Package

You only do Part 1 once, the very first time. After the package is installed, you never need to repeat these steps.

Step 1 - Log in to RStudio Server

Open your web browser and go to the RStudio Server URL your instructor gave you. Log in with your username and password. You should see the RStudio interface with a Console pane on the left.

Step 2 - Create a folder and upload the zip file

  1. In the Files pane (bottom right), click the Home icon (the little house)
  2. Click New Folder and name it exactly regional_climate_narratives (all lowercase, with underscores), then click OK
  3. Click the regional_climate_narratives folder to open it
  4. Click the Upload button (it has an upward arrow icon)
  5. Click Choose File, select Regional_Climate_Narratives--Student_Files.zip from your computer, and click OK

RStudio Server automatically unzips the file for you, so the files land directly inside regional_climate_narratives.

✅ Check The regional_climate_narratives folder should now contain Regional_Climate_Narratives_0.3.1.tar.gz, install_package.R, example_workflow.R, and the package reference. If you instead see the files sitting in your Home folder, you uploaded before opening the folder in step 3; move them into regional_climate_narratives (check the boxes, then More > Move).

Step 3 - Point R at that folder

In the Console (bottom left pane), type:

setwd("~/regional_climate_narratives")

Then verify the installer file is there:

file.exists("Regional_Climate_Narratives_0.3.1.tar.gz")

This must print TRUE. If it prints FALSE:

⚠️ Do not continue until file.exists(…) returns TRUE. Every installation problem in Step 5 traces back to this check being skipped.

Step 4 - Install the required packages (dependencies)

The package needs several other R packages to work. Install them first. Copy and paste this entire block into the Console and press Enter:

install.packages(c(
  "dplyr", "tidyr", "ggplot2", "lubridate",
  "sp", "sf", "gstat", "raster", "stars",
  "viridis", "maps", "mapdata", "patchwork"
))

This takes several minutes. You will see a lot of text scrolling by; that is normal. Wait until you see the > prompt again before continuing.

✅ Check After it finishes, look for any lines containing had non-zero exit status. That means a package failed to install. If you see it, note the package name and try installing it individually, e.g., install.packages(“sf”). If a package keeps failing, tell your instructor; it may need a system library installed on the server.

Step 5 - Install the Regional Climate Narratives package

Now install the actual package. Type:

install.packages("Regional_Climate_Narratives_0.3.1.tar.gz", repos = NULL, type = "source")

Wait for it to finish. The last lines should include:

* DONE (RegionalClimateNarratives)

If you see ERROR or had non-zero exit status instead: Read the error message. It usually names a missing package. Go back to Step 4 and install that package, then try Step 5 again.

Step 6 - Verify it works

Load the package. Note the name here has no underscores: R package names cannot contain them, so the package is RegionalClimateNarratives even though the files use Regional_Climate_Narratives:

library(RegionalClimateNarratives)

You should see this startup message:

===========================================================
 Regional Climate Narratives v0.3.1
===========================================================
 Regional Climate Trends Analysis and Visualization
 Type ?RegionalClimateNarratives for help
===========================================================

If you see a !!! warning about missing packages instead, run check_dependencies(), then try library(RegionalClimateNarratives) again.

✅ Part 1 complete If the startup message shows v0.3.1, the package is installed permanently on the server. You will not need to repeat Part 1.


Part 2: Download Your State’s Data

Do this once per state.

Step 7 - Initialize your project

initialize_project("XX")

Replace XX with your state code. For example:

initialize_project("CA")   # California
initialize_project("TX")   # Texas
initialize_project("NY")   # New York

What this does:

You should see output ending with Setup Complete! and a count of potential stations.

Step 8 - Select stations

select_stations(n = 50)

This picks the 50 stations with the longest, most complete records in your state.

Step 9 - Download data from NOAA

download_stations()

⏰ This takes 10 to 30 minutes. You will see progress for each station. You can keep working in another browser tab while it runs. If it gets interrupted (connection drops, you close your laptop, etc.), just run download_stations() again; it skips stations already downloaded.

Step 10 - Save data in efficient format

load_and_save_stations(cleanup = TRUE)

This converts the downloaded files into a single compressed file that loads much faster in the future. Setting cleanup = TRUE deletes the temporary files to save disk space.

Part 2 is done. Your data is saved to disk and ready for analysis.


Part 3: Analysis

What to do every time you open RStudio

When your R session ends (you log out, your session times out, or you restart R), all variables in memory are erased. Your files on disk are fine; they are saved permanently. But R needs to reload them.

🔑 Every new session starts with these three lines

library(RegionalClimateNarratives)
initialize_project("XX")     # your state code, e.g., "CA"
load_stations()
  • library(RegionalClimateNarratives) loads the package functions (they are not available until you do this)
  • initialize_project(“XX”) sets your working directory to ~/Regional_Climate_Narratives_XX/ and creates the path variables (datafolder, figuresfolder). This replaces any need to call setwd() yourself.
  • load_stations() loads your previously saved weather data from the Data/ folder back into memory

You do NOT need to call setwd(), re-download anything, or re-install the package.

Step 12 - Create spatial objects

create_spatial_objects(trends)

This converts your trend data into a spatial format that can be mapped.


Part 3 (continued): Heat Maps

Step 13 - Make heat maps

Annual maximum temperature trend:

map_tmax <- create_heatmap(
  trends_sp,
  trend_var = "annual_trend_TMAX",
  title = paste(my.state, "- Annual Maximum Temperature Trend"),
  subtitle = "Change in degrees C per 100 years",
  state = my.state,
  colors = "temp"
)
print(map_tmax)

Save it as a high-resolution image:

ggsave(paste0(figuresfolder, "TMAX_annual_", my.state, ".png"),
       map_tmax, width = 10, height = 8, dpi = 300)

The file saves into your Figures/ folder. Find it in the Files pane under ~/Regional_Climate_Narratives_XX/Figures/.

Annual minimum temperature trend:

map_tmin <- create_heatmap(
  trends_sp,
  trend_var = "annual_trend_TMIN",
  title = paste(my.state, "- Annual Minimum Temperature Trend"),
  subtitle = "Change in degrees C per 100 years",
  state = my.state,
  colors = "temp"
)
ggsave(paste0(figuresfolder, "TMIN_annual_", my.state, ".png"),
       map_tmin, width = 10, height = 8, dpi = 300)

Precipitation trend (uses a different color scheme):

map_prcp <- create_heatmap(
  trends_sp,
  trend_var = "annual_trend_PRCP",
  title = paste(my.state, "- Annual Precipitation Trend"),
  subtitle = "Change in mm per 100 years",
  state = my.state,
  colors = "precip"
)
ggsave(paste0(figuresfolder, "PRCP_annual_", my.state, ".png"),
       map_prcp, width = 10, height = 8, dpi = 300)

Step 14 - Seasonal comparison (4-panel map)

library(patchwork)

winter_map <- create_heatmap(trends_sp, "winter_trend_TMAX",
              "Winter (Dec-Feb)", state = my.state, resolution = 0.15) +
  theme(legend.position = "none")

spring_map <- create_heatmap(trends_sp, "spring_trend_TMAX",
              "Spring (Mar-May)", state = my.state, resolution = 0.15) +
  theme(legend.position = "none")

summer_map <- create_heatmap(trends_sp, "summer_trend_TMAX",
              "Summer (Jun-Aug)", state = my.state, resolution = 0.15) +
  theme(legend.position = "right")

fall_map <- create_heatmap(trends_sp, "fall_trend_TMAX",
            "Fall (Sep-Nov)", state = my.state, resolution = 0.15) +
  theme(legend.position = "none")

seasonal_panel <- (winter_map | spring_map) / (summer_map | fall_map) +
  plot_annotation(
    title = paste("Seasonal TMAX Trends -", my.state),
    subtitle = "Change in degrees C per 100 years by season"
  )

ggsave(paste0(figuresfolder, "Seasonal_TMAX_", my.state, ".png"),
       seasonal_panel, width = 12, height = 10, dpi = 300)

Quick-start template (after Parts 1 and 2 are done)

Copy this block, change the state code on line 2, and run it:

library(RegionalClimateNarratives)
initialize_project("CA")     # <-- CHANGE THIS TO YOUR STATE
load_stations()

trends <- process_all_stations()
create_spatial_objects(trends)

map <- create_heatmap(trends_sp, "annual_trend_TMAX",
       paste(my.state, "Annual TMAX Trend"), state = my.state)
print(map)
ggsave(paste0(figuresfolder, "TMAX_", my.state, ".png"),
       map, width = 10, height = 8, dpi = 300)

Understanding Your Results

🌡️ Normals, anomalies, and trends A normal is the average value for each month over a 30-year baseline period; the standard is 1961–1990 (set by the World Meteorological Organization). If a station does not have enough data in that window, the package uses a later period and tells you. An anomaly is the observed value minus the normal: positive means warmer (or wetter) than the baseline average, negative means cooler (or drier). A trend is the slope of a line fitted through the anomalies over time, reported as change per century.

Anomaly = Observed value − Normal TMAX trend of +1.5 degrees C/century = max temperatures increased ~1.5 degrees C over 100 years
PRCP trend of −25 mm/century = annual precipitation decreased ~25 mm over 100 years

💬 What to look for in your maps

  1. Is your state warming uniformly, or are some regions warming faster?
  2. Is nighttime warming (TMIN) different from daytime warming (TMAX)?
  3. Do seasonal patterns differ? (Many states warm more in winter than summer.)
  4. Is precipitation increasing, decreasing, or mixed across your state?

Reference

Available heat map variables

Variable What it shows
annual_trend_TMAX Annual maximum temperature trend
annual_trend_TMIN Annual minimum temperature trend
annual_trend_PRCP Annual precipitation trend
winter_trend_TMAX Winter (Dec-Feb) max temp trend
spring_trend_TMAX Spring (Mar-May) max temp trend
summer_trend_TMAX Summer (Jun-Aug) max temp trend
fall_trend_TMAX Fall (Sep-Nov) max temp trend

Replace TMAX with TMIN or PRCP for min temperature or precipitation versions.

What happens when you close RStudio

What Saved to disk? What to do next session
The RegionalClimateNarratives package Yes, installed permanently Run library(RegionalClimateNarratives)
Your downloaded weather data Yes, in ~/Regional_Climate_Narratives_XX/Data/ Run load_stations()
Your saved heat map images Yes, in ~/Regional_Climate_Narratives_XX/Figures/ Nothing; the PNG files are already saved
Variables in memory (trends, my.state, map_tmax, etc.) No, R clears memory Re-run initialize_project() and load_stations()
Your working directory setting No, resets when session ends initialize_project() sets it for you

Getting help

?initialize_project          # Help for a specific function
?RegionalClimateNarratives           # Package overview
help(package = "RegionalClimateNarratives")   # List all functions

If you are stuck, show your instructor the exact error message. Copy the red text from the Console.


Troubleshooting

file.exists(...) returns FALSE in Step 3

The installer file is not in your current working directory. Check:

  1. Did you upload the zip? (Part 1, Step 2)
  2. Are the files inside regional_climate_narratives? Check the Files pane.
  3. Did you run setwd("~/regional_climate_narratives")? Run getwd() to see where R is looking.

“there is no package called …”

A required package is missing. Install it:

install.packages("sf")   # replace with the package name from the error

Or install all dependencies at once (copy-paste from Part 1, Step 4). Or run the included installer script, which handles everything with pass/fail reporting:

setwd("~/regional_climate_narratives")
source("install_package.R")

“Run initialize_project() first!”

You need to run initialize_project("XX") at the start of every R session. This is the most common error. It just means you started a new session and forgot the setup lines.

“RData file not found”

Your data has not been downloaded yet, or the download did not finish. Go back to Part 2 (Steps 8-10).

“could not find function ‘process_all_stations’”

Either the package is not loaded, or an old version is installed. Try:

library(RegionalClimateNarratives)

If that does not help, reinstall:

setwd("~/regional_climate_narratives")
install.packages("Regional_Climate_Narratives_0.3.1.tar.gz", repos = NULL, type = "source")

Then go to Session > Restart R in the RStudio menu, and try library(RegionalClimateNarratives) again.

Download seems stuck

NOAA servers can be slow. For 50 stations, expect 10 to 30 minutes. If it stops with errors, run download_stations() again. It skips stations already downloaded.

Messages about normals periods

"Normals period = 1971-2000" is informational. The station is still analyzed. This is not an error.

Warning about skipped stations

"Cannot compute normals for TMAX. Skipping." means that station did not have enough data. A few skipped stations is expected.

Heat map looks odd

Where are my files?

Run getwd() to see your current project folder. Your files are in Data/ (weather data), Figures/ (saved heat maps), and Output/ (analysis results). Or navigate in the Files pane (bottom right of RStudio).