Skip to content

Instantly share code, notes, and snippets.

@natbusa
Created October 14, 2013 14:58
Show Gist options
  • Save natbusa/6977041 to your computer and use it in GitHub Desktop.
Save natbusa/6977041 to your computer and use it in GitHub Desktop.
A gist about displaying intervals using R and ggplot
library("ggplot2")
logfile = "
task a,2,9
task b,3,8
task c,1,4
task d,5,12
"
# read in the sample logfile in a data frame
df = read.csv(
text=logfile,
header=FALSE,
sep = ",",
stringsAsFactors=FALSE,
blank.lines.skip=TRUE
)
# give the column a proper name
names(df)=c('name', 'start','end')
# display the timeline intervals sorted by start time
# display the timeline intervals sorted by start time
ggplot(df, aes(start, reorder(name, -start), colour = name)) +
geom_errorbarh(aes(xmin = start,xmax = end, height = 0.2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment