Skip to content

Instantly share code, notes, and snippets.

@benmarwick
Created April 12, 2024 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benmarwick/d0789be8014bb8dd079dd8c57cc587ea to your computer and use it in GitHub Desktop.
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
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")
@benmarwick
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment