Created
June 20, 2026 12:22
-
-
Save thoughtfulbloke/81c8cd5ea2af7209968e8217aa620638 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(dplyr) | |
| library(lubridate) | |
| library(ggplot2) | |
| source("~/theme.R") | |
| # skimr::skim(cycle_all) | |
| # | |
| # ── Data Summary ──────────────────────── | |
| # Values | |
| # Name cycle_all | |
| # Number of rows 5436 | |
| # Number of columns 4 | |
| # _______________________ | |
| # Column type frequency: | |
| # character 2 | |
| # Date 1 | |
| # numeric 1 | |
| # ________________________ | |
| # Group variables None | |
| # | |
| # ── Variable type: character ───────────────────────────── | |
| # skim_variable n_missing complete_rate min max empty | |
| # 1 Transport 0 1 12 12 0 | |
| # 2 subdivision 0 1 13 48 0 | |
| # n_unique whitespace | |
| # 1 1 0 | |
| # 2 18 0 | |
| # | |
| # ── Variable type: Date ────────────────────────────────── | |
| # skim_variable n_missing complete_rate min | |
| # 1 adjusted_date 0 1 2025-01-01 | |
| # max median n_unique | |
| # 1 2026-05-31 2025-09-15 302 | |
| # | |
| # ── Variable type: numeric ─────────────────────────────── | |
| # skim_variable n_missing complete_rate mean sd p0 p25 | |
| # 1 daily_subtotal 0 1 140. 122. 0 54 | |
| # p50 p75 p100 hist | |
| # 1 105 189. 1243 ▇▁▁▁▁ | |
| monthed <- cycle_all |> | |
| summarise(.by=adjusted_date, | |
| totals = sum(daily_subtotal)) |> | |
| mutate(monthly = floor_date(adjusted_date, unit = "month")) | |
| densed <- function(x, datacombo = monthed){ | |
| partial = datacombo |> filter(monthly == x) | |
| d = density(partial$totals) | |
| df <- data.frame( | |
| x = d$x, | |
| y = d$y | |
| ) | |
| df$monthis = x | |
| return(df) | |
| } | |
| denser <- bind_rows(lapply(unique(monthed$monthly), densed)) | |
| densest <- denser |> | |
| filter(x > 0) |> | |
| mutate(Month = month(monthis), | |
| Year = year(monthis), | |
| xadjust = ifelse(Year == 2026, | |
| .4 * y/max(y), | |
| -0.4 * y/max(y)), | |
| xcord = Month + xadjust, | |
| ycord=x) |> | |
| select(monthis,Month,Year,xcord,ycord) | |
| top_edge = densest |> | |
| summarise(.by=c(monthis,Month,Year), | |
| ycord=max(ycord)+.001) |> | |
| mutate(xcord=Month) | |
| bottom_edge = top_edge |> | |
| mutate(ycord=0) | |
| grfpols <- bind_rows(densest, top_edge, bottom_edge) |> | |
| arrange(ycord) |> | |
| mutate(Year=factor(Year)) | |
| monthmeans <- monthed |> | |
| summarise(.by=monthly, | |
| ycord=mean(totals)) |> | |
| mutate(Year = factor(year(monthly)), | |
| Month = month(monthly), | |
| xcord = ifelse(Year == "2026", | |
| Month + 0.4, Month -0.4)) | |
| ggplot(grfpols) + | |
| geom_polygon(aes(x=xcord,y=ycord, group=monthis, | |
| fill=Year)) + | |
| theme_david() + | |
| geom_segment(data=monthmeans, aes(x=xcord,y=ycord,xend=Month,yend=ycord, linetype=Year)) + | |
| scale_linetype_discrete(name="Mean") + | |
| scale_fill_viridis_d(end=.85, name="Frequency") + | |
| labs(title="Ōtepoti/Dunedin Cycle Counts", | |
| y="Daily Totals", x=NULL, | |
| caption=make_footer("Source: DCC")) + | |
| scale_x_continuous(breaks=c(1,3,5), | |
| labels=c("Jan","Mar","May")) | |
| ggsave(filename="~/Desktop/ggsky.jpg", width=2016, height=1134, units="px") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment