Skip to content

Instantly share code, notes, and snippets.

@thoughtfulbloke
Created April 16, 2026 21:45
Show Gist options
  • Select an option

  • Save thoughtfulbloke/d23d97ebadb6b7513d138be5cfe042f4 to your computer and use it in GitHub Desktop.

Select an option

Save thoughtfulbloke/d23d97ebadb6b7513d138be5cfe042f4 to your computer and use it in GitHub Desktop.
library(dplyr)
library(tidyr)
library(readxl)
library(readr)
library(ggplot2)
library(lubridate)
library(slider)
source("~/theme.R")
p2 <- "https://www.trade.gov/i-94-arrivals-program"
p1 <- "I-94 monthly international visitor arrivals, 2000-present (Excel file)"
i94 = read_excel("~/Downloads/Monthly Arrivals 2000 to Present – Country of Residence (COR)_1.xlsx",
sheet="Monthly")
ilong <- i94 |>
select(Area=`International Visitors--\r\n 1) Country of Residence\r\n 2) 1+ nights in the USA\r\n 3) Among qualified visa types`,
280:318) |>
slice(2,20:254) |>
pivot_longer(2:40, names_to = "Mnth", values_to = "arrivals") |>
arrange(Area,Mnth) |>
group_by(Area) |>
mutate(roll12 = slide_dbl(arrivals,.f=mean,.before=11, .complete=TRUE)) |>
ungroup()
BASED <- ilong |>
filter(Mnth == "2024-11") |>
select(Area, baseline=roll12) |>
inner_join(ilong, by = join_by(Area)) |>
mutate(v2411 = 100*roll12/baseline,
Dated = ymd(paste0(substr(Mnth,1,7),"-15"))) |>
filter(!is.na(v2411), Dated > ymd("2024-11-1"))
interest <- BASED |>
filter(Area %in% c("Australia", "Canada", "New Zealand",
"Denmark", "Hungary", "TOTAL ALL COUNTRIES")) |>
mutate(Area = ifelse(Area == "TOTAL ALL COUNTRIES", "TOTAL ARRIVALS", Area))
labpoints <- interest |>
arrange(Area,desc(Dated)) |>
group_by(Area) |>
slice(1) |>
ungroup() |>
mutate(Dated = max(Dated) + days(15))
ggplot(BASED, aes(x=Dated, y=v2411)) +
geom_line(aes(group=Area), linewidth=0.03, alpha=0.3) +
theme_david() + theme(legend.position = "none")+
scale_colour_manual(values = six_cols[c(2,3,2,1,1,3)]) +
scale_x_date(breaks=as.Date(c("2024-11-15","2025-7-15","2026-3-15")),
date_labels = "%b %y") +
scale_linetype_manual(values=c(2,1,1,2,1,2))+
scale_discrete_manual(aesthetics = "vjust", values = c(1,.5,.5,.5,.5,0))+
coord_cartesian(ylim=c(70,115),
xlim=c(NA_Date_,as.Date("2026-7-1")))+
geom_line(data=interest, aes(colour=Area, linetype=Area)) +
geom_text(data=labpoints,
aes(colour=Area, label=Area, vjust=Area), size=3,hjust=0) +
labs(x=NULL, y="Arrivals as % of Nov 2024",
title="Rolling 12 month I-94 visitors to the US, as percentage of Nov 2024",
caption=make_footer(paste0("Source: ",p1,"\n",p2)))
ggsave("~/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