203 lines
6.5 KiB
R
203 lines
6.5 KiB
R
|
|
library(ggplot2)
|
|
library(tidyr)
|
|
library(dplyr)
|
|
library(forcats)
|
|
library(ggthemes)
|
|
library(plotly)
|
|
library(htmlwidgets)
|
|
library(lubridate)
|
|
|
|
# Read in data from Wayback Machine archive of http://www.arrl.org/fcc-license-counts
|
|
|
|
d_raw <- read.csv("data/us ham radio licenses over time.csv")
|
|
|
|
# What dates do we have?
|
|
unique(d_raw$Date)
|
|
|
|
# Clean up here if needed
|
|
d <- d_raw %>%
|
|
mutate(Date = as.Date(Date)) #%>%
|
|
# Drop Tech alone and leave Tech and Tech Plus
|
|
#select(-c(Tech, Tech.Plus))
|
|
|
|
d_total <- d %>% filter(State.Territory == "TOTAL")
|
|
|
|
d_total_long <- d_total %>%
|
|
pivot_longer(cols = !c("Date", "State.Territory", "source_name", "source_detail"),
|
|
names_to = "lclass",
|
|
values_to = "count") %>%
|
|
# only keep rows with data so plots look right
|
|
filter(!is.na(count))
|
|
|
|
d_state_total_long <- d %>% filter(State.Territory != "TOTAL") %>%
|
|
select(Date, State.Territory, Total, source_name, source_detail) %>%
|
|
filter(!is.na(Total))
|
|
|
|
#### Plots ####
|
|
|
|
##### Total over time, y = 0 #####
|
|
ggplot(data = d_total,
|
|
aes(x = Date,
|
|
y = Total,
|
|
color = source_name)) +
|
|
geom_line() +
|
|
geom_point(size = 0.3) +
|
|
scale_x_date(date_breaks = "10 years",
|
|
date_minor_breaks = "1 year",
|
|
date_labels = "%Y") +
|
|
scale_y_continuous(labels = scales::comma,
|
|
limits = c(0, NA)) +
|
|
theme_bw() +
|
|
labs(title = "US Amateur Licenses",
|
|
caption = "w1cdn.net",
|
|
color = "Source") +
|
|
theme(legend.position="bottom")
|
|
ggplotly()
|
|
|
|
ggsave("plots/total-over-time-y.png", width = 6, height = 4)
|
|
|
|
p <- ggplotly()
|
|
htmlwidgets::saveWidget(as_widget(p), selfcontained = TRUE, file = "plots/total-over-time-y.html")
|
|
|
|
##### Total over time, since 2000 #####
|
|
ggplot(data = d_total %>% filter(Date >= as.Date("2000-01-01")),
|
|
aes(x = Date,
|
|
y = Total,
|
|
color = source_name)) +
|
|
geom_line() +
|
|
geom_point(size = 0.3) +
|
|
scale_x_date(date_breaks = "2 years",
|
|
date_minor_breaks = "3 months",
|
|
date_labels = "%Y") +
|
|
scale_y_continuous(labels = scales::comma) +
|
|
theme_bw() +
|
|
labs(title = "US Amateur Licenses since 2000",
|
|
caption = "w1cdn.net",
|
|
color = "Source") +
|
|
theme(legend.position="bottom")
|
|
|
|
ggsave("plots/total-over-time-2000.png", width = 6, height = 4)
|
|
|
|
##### Total over time, 2 years #####
|
|
ggplot(data = d_total %>% filter(Date >= Sys.Date() - years(2)),
|
|
aes(x = Date,
|
|
y = Total,
|
|
color = source_name)) +
|
|
geom_line() +
|
|
geom_point(size = 0.3) +
|
|
scale_x_date(date_breaks = "3 months",
|
|
date_minor_breaks = "1 month",
|
|
date_labels = "%Y-%m") +
|
|
scale_y_continuous(labels = scales::comma) +
|
|
theme_bw() +
|
|
labs(title = paste0("US Amateur Licenses since ", Sys.Date() - years(2)),
|
|
caption = "w1cdn.net",
|
|
color = "Source") +
|
|
theme(legend.position="bottom")
|
|
|
|
ggsave("plots/total-over-time-2-years.png", width = 6, height = 4)
|
|
|
|
##### By license class #####
|
|
ggplot(data = d_total_long %>% filter(lclass != "Total"),
|
|
aes(x = Date,
|
|
y = count,
|
|
color = fct_reorder2(lclass, Date, count))) +
|
|
geom_line() +
|
|
geom_point(size = 0.3) +
|
|
scale_x_date(date_breaks = "10 years",
|
|
date_minor_breaks = "1 year",
|
|
date_labels = "%Y") +
|
|
scale_y_continuous(labels = scales::comma) +
|
|
scale_color_colorblind() +
|
|
theme_bw() +
|
|
labs(title = "US Amateur Licenses by Class",
|
|
y = "Count",
|
|
color = "Class",
|
|
caption = "w1cdn.net") +
|
|
theme(legend.position="bottom")
|
|
|
|
ggsave("plots/class-over-time.png", width = 6, height = 4)
|
|
|
|
##### By license class, 2 years #####
|
|
ggplot(data = d_total_long %>% filter(lclass != "Total",
|
|
Date >= Sys.Date() - years(2)),
|
|
aes(x = Date,
|
|
y = count,
|
|
color = fct_reorder2(lclass, Date, count))) +
|
|
geom_line() +
|
|
geom_point(size = 0.3) +
|
|
scale_x_date(date_breaks = "10 years",
|
|
date_minor_breaks = "1 year",
|
|
date_labels = "%Y") +
|
|
scale_y_continuous(labels = scales::comma) +
|
|
scale_color_colorblind() +
|
|
theme_bw() +
|
|
labs(title = paste0("US Amateur Licenses by Class since ", Sys.Date() - years(2)),
|
|
y = "Count",
|
|
color = "Class",
|
|
caption = "w1cdn.net") +
|
|
theme(legend.position="bottom")
|
|
|
|
ggsave("plots/class-over-time-2-years.png", width = 6, height = 4)
|
|
|
|
##### By license class, facet #####
|
|
ggplot(data = d_total_long %>% filter(lclass != "Total"),
|
|
aes(x = Date,
|
|
y = count)) +
|
|
geom_line() +
|
|
geom_point(size = 0.3) +
|
|
facet_wrap(~lclass) +
|
|
scale_x_date(date_breaks = "10 years",
|
|
date_minor_breaks = "1 year",
|
|
date_labels = "%Y") +
|
|
scale_y_continuous(labels = scales::comma) +
|
|
scale_color_colorblind() +
|
|
theme_bw() +
|
|
labs(title = "US Amateur Licenses by Class",
|
|
y = "Count",
|
|
color = "Class",
|
|
caption = "w1cdn.net") +
|
|
theme(legend.position="bottom")
|
|
|
|
ggsave("plots/class-over-time-facet.png", width = 15, height = 9)
|
|
|
|
##### By license class, stacked #####
|
|
# ggplot(data = d_total_long %>% filter(lclass != "Total"),
|
|
# aes(x = Date,
|
|
# y = count,
|
|
# fill = fct_reorder2(lclass, Date, count))) +
|
|
# geom_area() +
|
|
# scale_fill_colorblind() +
|
|
# scale_x_date(date_breaks = "10 years",
|
|
# date_minor_breaks = "1 year",
|
|
# date_labels = "%Y") +
|
|
# scale_y_continuous(labels = scales::comma) +
|
|
# theme_bw() +
|
|
# labs(title = "US Amateur Licenses by Class",
|
|
# fill = "Class",
|
|
# caption = "w1cdn.net") +
|
|
# theme(legend.position="bottom")
|
|
|
|
#ggsave("plots/class-over-time-stacked.png", width = 6, height = 4)
|
|
|
|
##### By state #####
|
|
ggplot(data = d_state_total_long,
|
|
aes(x = Date,
|
|
y = Total)) +
|
|
geom_line() +
|
|
geom_point(size = 0.3) +
|
|
facet_wrap(~State.Territory,
|
|
scales = "free_y") +
|
|
scale_x_date(date_breaks = "10 years",
|
|
#date_minor_breaks = "1 year",
|
|
date_labels = "%Y") +
|
|
scale_y_continuous(labels = scales::comma) +
|
|
theme_bw() +
|
|
labs(title = "US Amateur Licenses by State",
|
|
y = "Count",
|
|
caption = "w1cdn.net") +
|
|
theme(legend.position="bottom")
|
|
|
|
ggsave("plots/states-over-time-freey.png", width = 15, height = 9)
|