Skip to content

Instantly share code, notes, and snippets.

@crsh
Created May 7, 2015 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save crsh/4f9ce67f408611bc3974 to your computer and use it in GitHub Desktop.
Save crsh/4f9ce67f408611bc3974 to your computer and use it in GitHub Desktop.
Add events with time frame to plot.gantt()
# Function definition
add_event <- function(start, end = NULL, label = NULL, line = 0.5, las = 1, col = scales::alpha("steelblue", 0.5)) {
if(is.null(end)) {
end <- paste(start, "23:59:59")
start <- paste(start, "00:00:00")
}
start <- as.POSIXct(start)
end <- as.POSIXct(end)
rect(start, 0, end, 100, col = col, border = FALSE)
mtext(label, at = mean.POSIXct(c(start, end)), line = line, las = las, cex = 0.9)
invisible(0)
}
# Example
library("plan")
data("gantt")
plot(gantt)
add_event(start = "2008-12-24", label = "X-Mas", col = "red")
add_event(start = "2008-06-15", end = "2008-07-15", label = "Summer vacation")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment