Created
May 7, 2015 16:04
-
-
Save crsh/4f9ce67f408611bc3974 to your computer and use it in GitHub Desktop.
Add events with time frame to plot.gantt()
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
# 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