Skip to content

Instantly share code, notes, and snippets.

@PaulC91
Last active June 12, 2018 16:35
Show Gist options
  • Save PaulC91/ec4143d29bb19b7176d38eace018e4ff to your computer and use it in GitHub Desktop.
Save PaulC91/ec4143d29bb19b7176d38eace018e4ff to your computer and use it in GitHub Desktop.
map your record collection with the discogger R package
library(discogger)
library(tidyverse)
library(sf)
library(rnaturalearth)
library(countrycode)
library(scico)
my_records <- discogs_user_collection("pacampbell91")
my_releases <- map_chr(my_records$content, "id") %>%
map(~ discogs_release(.x))
geos <-
tibble(
country = map_chr(map(my_releases, "content"), "country", .null = NA_character_),
) %>%
count(country) %>%
mutate(iso3 = countrycode::countrycode(country, "country.name", "iso3c")) %>%
filter(!is.na(iso3))
world_robinson <- rnaturalearth::ne_countries(returnclass = "sf") %>%
st_transform(crs = "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84") %>%
filter(!name %in% c("Fr. S. Antarctic Lands", "Antarctica"))
discmap <- geos %>%
full_join(world_robinson, c("iso3" = "adm0_a3")) %>%
st_as_sf()
ggplot(discmap) +
geom_sf(aes(fill = n), colour = "#d3d3d3") +
scale_fill_scico(palette = "lajolla", na.value = "white",
trans = "log2", name = "# Records") +
coord_sf(datum = NA) +
labs(title = "Records Owned by Country of Release",
subtitle = "log2 scale",
caption = "Data sourced from discogs API") +
theme_void(base_family = "Iosevka") +
theme(plot.title = element_text(hjust = 0.5)) +
theme(plot.subtitle = element_text(hjust = 0.5)) +
theme(legend.position = "bottom")
@PaulC91
Copy link
Author

PaulC91 commented Jun 12, 2018

discmap

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