Created
April 12, 2024 05:54
-
-
Save benmarwick/d0789be8014bb8dd079dd8c57cc587ea to your computer and use it in GitHub Desktop.
Get data from the SOTA api to plot how many activations have been logged in each region of an association
This file contains 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(rvest) | |
library(httr) | |
library(tidyverse) | |
# get list of regions in the W7W association | |
# via API | |
sota_regions_w7w <- "https://api2.sota.org.uk/api/associations/w7w" | |
r <- GET(sota_regions_w7w) | |
dat <- | |
jsonlite::fromJSON(content(r, as = "text")) %>% | |
purrr::pluck("regions") %>% | |
tibble() | |
# get data on number of activations in each region in W7W | |
region_urls <- paste0("https://api2.sota.org.uk/api/regions/W7W/", | |
dat$regionCode) | |
# get all the data for each region, this take a few seconds | |
region_summits <- | |
map_dfr(region_urls, | |
~GET(.x) %>% | |
content(., as = "text")%>% | |
jsonlite::fromJSON() %>% | |
purrr::pluck("summits") %>% | |
tibble() ) | |
# plot them | |
region_summits %>% | |
mutate(region = str_remove_all(shortCode, "-.*")) %>% | |
group_by(region) %>% | |
summarise(sum_activationCount = sum(activationCount)) %>% | |
arrange(desc(sum_activationCount)) %>% | |
ggplot() + | |
aes(reorder(region, | |
-sum_activationCount), | |
sum_activationCount) + | |
geom_col() + | |
xlab("SOTA region") + | |
ylab("Number of activations") | |
Author
benmarwick
commented
Apr 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment