Skip to content

Instantly share code, notes, and snippets.

@vgXhc
Created January 25, 2025 14:15
Show Gist options
  • Save vgXhc/4e75cf57528fe9e212d7284dba58eaf7 to your computer and use it in GitHub Desktop.
Save vgXhc/4e75cf57528fe9e212d7284dba58eaf7 to your computer and use it in GitHub Desktop.
R code to make a chart that compares historic average temperatures in Madison in January and February
library(tidyverse)
clim <- read_csv("c:/Users/user1/Downloads/StnData.csv", col_names = c("date",
"avg",
"hi",
"lo"))
clim |> group_by(yr = year(date), mo = month(date, label = T, abbr = TRUE)) |>
summarize(avg_temp = mean(avg)) |>
filter(mo %in% c("Jan", "Feb")) |>
pivot_wider(names_from = mo, values_from = avg_temp) |>
mutate(feb_warmer = if_else(Feb > Jan, TRUE, FALSE)) |>
ggplot() +
geom_segment(aes(x = yr, xend = yr, y = Jan, yend = Feb, color = feb_warmer), arrow = arrow(length = unit(2, "mm"))) +
hrbrthemes::scale_color_ipsum(name = "Feb warmer than Jan?")+
labs(title = "Monthly average temperatures in January and February",
subtitle = "Madison, Wisconsin",
caption = "Source: https://climatology.nelson.wisc.edu/first-order-station-climate-data/madison-climate/historical-temperatures/") +
xlab("Year") +
ylab("°F") +
hrbrthemes::theme_ft_rc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment