Skip to content

Instantly share code, notes, and snippets.

@philippbayer
Created October 24, 2019 03:07
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 philippbayer/af383f88cf8786c3bc314b3db3954ba3 to your computer and use it in GitHub Desktop.
Save philippbayer/af383f88cf8786c3bc314b3db3954ba3 to your computer and use it in GitHub Desktop.
Plots a ggridges plot of fruitstatus
library(tidyverse)
library(lubridate)
library(viridis)
library(ggridges)
# fix typos
a <- read_csv('./biiiiirdsssss.csv')
a$date <- gsub("16/01/017", "16/01/2017", a$date)
a$date <- gsub("26/07/2026", "26/07/2016", a$date)
a$date <- dmy(a$date)
# a has headers treeID, site, habitat, species, date, unripe, ripe, overripe,
# This needs tidyr v1.0!!!
long_a <- a %>% pivot_longer(
cols = contains('ripe'),
names_to = 'fruitstatus',
values_to = 'count'
)
long_a %>% filter(species == 'capelilac') %>%
arrange(date) %>%
# turn the date into factor, reverse the factor
ggplot(aes(y=fct_rev(factor(date)))) +
# make the geoms, set lines to white
geom_density_ridges(aes(x=count, fill=fruitstatus),
alpha = .5, color = "white", from = 0, to = 100) +
# stretch the plot to connect to the edges
scale_x_continuous(expand = c(0.01, 0)) +
labs(
x = 'Percentage',
y = 'Date of measurement'
) +
scale_y_discrete(expand = c(0.01, 0)) +
scale_fill_viridis(discrete = T, direction = -1) +
theme_ridges()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment