Last active
June 12, 2018 16:35
-
-
Save PaulC91/ec4143d29bb19b7176d38eace018e4ff to your computer and use it in GitHub Desktop.
map your record collection with the discogger R package
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(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") |
Author
PaulC91
commented
Jun 12, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment