Fopa Léon Constantin
Fopa Léon Constantin

Reputation: 12373

How to plot such a graph in R?

I've data in a csv file with the following format :

start;duration
1;4
7;3
15;2

that's means we have 3 tasks, the first start at 1 and takes 4 seconds (so it end at 5), the second start a 7 and takes 3 second (soo ended at 10) and the last starts at 15 and take 2 seconds

How to reprensent these information in a graph which look like this enter image description here

Upvotes: 2

Views: 667

Answers (1)

IRTFM
IRTFM

Reputation: 263471

 dat <- read.csv2(text="start;duration
 1;4
 7;3
 15;2
 ")
 plot(NA, xlim=c(0,20), ylim=c(0,9), ylab="",xlab="X", xaxt="n", yaxt="n")
 with(dat, segments(x0=start, x1=start+duration, y0=2,y1=2))
 with(dat, text( start+duration/2, 2.5, labels=duration))
 axis(1, at=seq(0,20,by=2), labels=seq(0,20,by=2))

You could obviously put in more descriptive labels for ylab and xlab in the plot call but this is what you get with that minimal example:

enter image description here

Upvotes: 8

Related Questions