Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(tidyverse)
- library(rcartocolor)
- rp <- read_csv("rank-project.csv") %>%
- drop_na(Phenotype)
- names(rp) <- c("reanalyzed_by", "orig_author", "phenotype", "sex", "analysis",
- "better_than_null", "aic_null", "aic_ord", "aic_prop",
- "delta_aic_ord_prop", "abs_delta", "detection")
- rp$is_juv <- str_detect(rp$sex, "J")
- rp$sex <- fct_collapse(rp$sex,
- Female = c("F", "JF"),
- Male = c("M", "JM"),
- Both = "J")
- rp$sex <- factor(rp$sex, levels = c("Female", "Male", "Both"))
- rp$is_juv <- factor(rp$is_juv, levels = c("FALSE", "TRUE"),
- labels = c("Adults", "Juveniles"))
- rp <- rp %>%
- mutate(phenotype = str_replace(phenotype, fixed(" (juv)"), ""),
- phenotype = fct_reorder(phenotype, desc(abs_delta)))
- lim <- max(rp$abs_delta, na.rm = TRUE)
- plot_data <- filter(rp, better_than_null == 1)
- pd_neg <- plot_data %>%
- filter(delta_aic_ord_prop < 0) %>%
- rowwise() %>%
- mutate(lab = min(delta_aic_ord_prop, -2)) %>%
- ungroup()
- pd_pos <- plot_data %>%
- filter(delta_aic_ord_prop > 0) %>%
- rowwise() %>%
- mutate(lab = max(delta_aic_ord_prop, 2)) %>%
- ungroup()
- # Orange and blue
- # fill_cols <- carto_pal(12, "Bold")[c(7, 8, 4)]
- # Green and purple
- fill_cols <- carto_pal(12, "Bold")[c(1, 2, 4)]
- ggplot() +
- geom_col(data = plot_data,
- aes(x = phenotype, y = delta_aic_ord_prop,
- fill = sex, alpha = is_juv), width = 0.8) +
- # annotate(geom = "rect", xmin = 0, xmax = Inf, ymin = -2, ymax = 2,
- # fill = "gray20", alpha = 0.5) +
- annotate(geom = "segment", x = 0, xend = Inf, y = 0, yend = 0) +
- annotate(geom = "segment", x = 0, xend = Inf, y = -2, yend = -2,
- lty = 3, color = "gray20") +
- annotate(geom = "segment", x = 0, xend = Inf, y = 2, yend = 2,
- lty = 3, color = "gray20") +
- geom_text(data = pd_pos,
- aes(x = phenotype, y = lab,
- label = phenotype), nudge_y = 0.5, hjust = 0,
- color = "gray50", size = 3.5) +
- geom_text(data = pd_neg,
- aes(x = phenotype, y = lab,
- label = phenotype), nudge_y = -0.5, hjust = 1,
- color = "gray50", size = 3.5) +
- annotate(geom = "text", label = expression(phantom(x) %<-% Ordinal~Rank~Better),
- x = "Sexual swelling length", y = -34, hjust = 0, size = 6) +
- annotate(geom = "text", label = expression(Proportional~Rank~Better %->% phantom(x)),
- x = "Sexual swelling length", y = 34, hjust = 1, size = 6) +
- coord_flip() +
- scale_y_continuous(limits = c(-lim - 7, lim + 7),
- breaks = sort(c(-2, 2, seq(-30, 30, by = 10)))) +
- scale_fill_manual(values = fill_cols, name = "Sex") +
- scale_alpha_manual(values = c(1, 0.5), name = NULL) +
- labs(x = NULL, y = expression(Delta~"AIC")) +
- theme_classic() +
- theme(axis.line.y = element_blank(),
- axis.text.y = element_blank(),
- axis.ticks.y = element_blank(),
- axis.text.x = element_text(size = 10),
- axis.title.x = element_text(size = 12),
- legend.position = "bottom")
- ggsave("rank-plot-mardi-gras.pdf", width = 11, height = 7, units = "in")
Add Comment
Please, Sign In to add comment