Skip to content

Instantly share code, notes, and snippets.

@cherfychow
Created November 8, 2023 04:16
Show Gist options
  • Save cherfychow/7aa53bad4ccfb033986c51afd9837f6d to your computer and use it in GitHub Desktop.
Save cherfychow/7aa53bad4ccfb033986c51afd9837f6d to your computer and use it in GitHub Desktop.
##############################
# Gantt Chart ggplot code
##############################
setwd("Pathnamehere")
source('https://gist.githubusercontent.com/cherfychow/e9ae890fd16f4c86730748c067feee2b/raw/b2db138ab8164c237129308ea643de78cd54b252/cherulean.R')
require(dplyr)
require(ggplot2)
# timeline
sched <- read.csv('researchtimeline.csv', header=T)[1:4]
# milestones
papers <- read.csv('researchtimeline.csv', header=T) %>% filter(!spot_type == '')
sched <- sched %>% arrange(wp, start_date)
# order them manually
sched$activity <- factor(sched$activity, levels = c(sched$activity[6:4], sched$activity[1], sched$activity[3]))
ggplot(sched) +
geom_segment(aes(x = start_date, xend = end_date + 1,
y = activity, yend = activity, color = wp), lineend = 'round', size = 5) +
geom_label(data = papers, aes(x = spot_date, y = activity, label = spot_type), size = 3, fill = "white", color = 'black') +
scale_color_cherulean(palette = "spinus", discrete = T, name = '') +
scale_x_continuous(breaks = min(sched$start_date):max(sched$end_date + 1)) +
theme_bw(base_size = 13) + theme(panel.grid.minor = element_blank(), legend.position = 'bottom') +
labs(x = NULL, y = 'Research tasks')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment