knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(tableauphenologie) library(tidyverse)
# top species in each region top10species <- tableauphenologie::inatqc %>% group_by(region, taxon_species_name) %>% tally %>% arrange(region,desc(n)) %>% nest %>% mutate(top10 = map(data, head, 10)) %>% select(-data) %>% unnest(top10) count_taxa <- tableauphenologie::inatqc %>% mutate(julianday = lubridate::yday(observed_on)) %>% group_by(region, taxon_species_name, julianday) %>% tally count_taxa %>% semi_join(top10species %>% select(-n)) %>% ggplot(aes(x = julianday, y = n)) + geom_point() + facet_wrap(~region) chosen_species_range_days <- count_taxa %>% semi_join(top10species %>% select(-n)) %>% filter(region == "Mauricie") %>% summarize(jday = range(julianday)) %>% mutate(dayname = if_else(jday == min(jday), "start", "end")) %>% ungroup # count days in the "range" for each species nper_day <- chosen_species_range_days %>% pivot_wider(names_from = dayname, values_from = jday) %>% mutate(dayrange = map2(start, end, ~.x:.y)) %>% select(dayrange) %>% unnest(cols = c(dayrange)) %>% group_by(dayrange) %>% tally %>% # fill in missing days: right_join(tibble(dayrange = 1:365)) %>% replace_na(list(n = 0)) %>% arrange(dayrange)
p1 <- chosen_species_range_days %>% ggplot(aes(x = jday, y = taxon_species_name)) + geom_line(size = 10, col = "darkgreen") + theme_minimal() + coord_cartesian(xlim = c(0,365)) + labs(x = "Jour de l'année", y = NULL) p1
p2 <- nper_day %>% ggplot(aes(x = dayrange, y = n)) + geom_polygon() + theme_minimal() p1
p2
tableauphenologie::nper_day
Here's another idea
ten_count <- count_taxa %>% semi_join(top10species %>% select(-n), by = c("region", "taxon_species_name")) ten_count_complete <- ten_count %>% complete(nesting(region, taxon_species_name), julianday=1:365) ten_count_complete %>% ggplot(aes(x = julianday, y = taxon_species_name, fill = is.na(n))) + geom_tile() + facet_wrap(~region, scales = "free_y") + theme(axis.text.y = element_blank())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.