Created
January 22, 2020 21:02
-
-
Save slarge/093187455341aa208eed1aabef908e6a to your computer and use it in GitHub Desktop.
condition_plots.R
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(ggplot2) | |
library(dplyr) | |
library(patchwork) | |
library(forcats) | |
annualCondition <- read.csv("https://raw.githubusercontent.com/Laurels1/Condition/master/data/AnnualRelCond2018_GB.csv", | |
stringsAsFactors = FALSE) | |
speciesNames <- annualCondition %>% | |
dplyr::filter(sex == "F") %>% | |
group_by(Species) %>% | |
mutate(scaleCond = scale(MeanCond, scale = TRUE, center = TRUE)) | |
xs = quantile(speciesNames$scaleCond, seq(0,1, length.out = 6), na.rm = TRUE) | |
speciesNames <- speciesNames %>% | |
mutate(category = cut(scaleCond, breaks = xs, labels = c( "Poor Condition", | |
"Bad", | |
"Neutral", | |
"Good", | |
"Good Condition"))) | |
sortNames <- speciesNames %>% | |
filter(YEAR <= 2014) %>% | |
group_by(Species) %>% | |
summarize(total = sum(scaleCond)) %>% | |
arrange(total) %>% | |
mutate(Species = factor(Species, levels = unique(Species))) %>% | |
pull(Species) | |
speciesNames$Species <- factor(speciesNames$Species, levels = sortNames) | |
p1 <- ggplot(speciesNames, aes(x = YEAR, y = forcats::fct_rev(Species), fill = category)) + | |
geom_tile() + | |
coord_equal() + | |
scale_fill_brewer(palette = "RdBu", na.value = "black") + | |
theme_bw() + | |
theme(legend.position="bottom") | |
p2 <- ggplot(speciesNames, aes(x = YEAR, y = forcats::fct_rev(Species), fill = scaleCond)) + | |
geom_tile() + | |
coord_equal() + | |
scale_fill_viridis_c() + | |
theme_bw() + | |
theme(legend.position = "bottom") | |
p1 + p2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment