Skip to content

Instantly share code, notes, and snippets.

@iago-pssjd
Created August 24, 2021 15:17
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 iago-pssjd/887dbd79b3ce22c7df2a6ee76b6588cc to your computer and use it in GitHub Desktop.
Save iago-pssjd/887dbd79b3ce22c7df2a6ee76b6588cc to your computer and use it in GitHub Desktop.
Code for week 35 of #TidyTuesday 2021
# Get the Data
# Or read in the data manually
lemurs <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-08-24/lemur_data.csv')
taxonomy <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-08-24/taxonomy.csv')
library(tidyverse)
lemurs %>%
left_join(taxonomy %>%
mutate(taxon = if_else(taxon != "CMEAD", taxon, "CMED")),
by = "taxon") %>%
filter(!if_any(c(taxon, age_max_live_or_dead_y), is.na), birth_type != "Unk") %>%
mutate(common_name = if_else(common_name != "hybrid", common_name, paste0("hybrid (", latin_name, ")")),
common_name = reorder(common_name, age_max_live_or_dead_y, mean)) %>%
ggplot(aes(x = common_name, y = age_max_live_or_dead_y, fill = taxon)) +
geom_violin() +
facet_grid(cols = vars(birth_type), labeller = labeller(birth_type = \(x){ifelse(x == "CB", "Captive-born", "Wild-born")})) +
labs(x = "Strepsirrhine primate taxa", y = "Maximum age known the animals achieved",
title = "Maximum age distribution achieved by 27 strepsirrhine species per birth type", caption = "Data source: Duke Lemur Center Data") +
coord_flip() +
theme_bw() +
theme(legend.position = "none")
ggsave(filename = "/tmp/lem.png", device = "png", dpi = "retina", width = 10, height = 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment