I have a table:
> DT
id start end place
1: id1 2014-01-01 2014-02-01 town1
2: id1 2014-02-01 2014-04-01 town2
3: id2 2014-01-01 2014-02-01 town2
4: id2 2014-03-01 2014-05-01 town4
5: id3 2014-01-01 2015-02-01 town3
I need to plot a chart with X=timeline
, Y=id
and each row should be displayed as a series of bars (length depends on start and end dates, and color depends on place).
Graph example: (without timeline labels):
For example, I'm trying
ggplot(DT,aes(start,id,colour=place))+geom_bar()
Of course it doesn't work
stat_count() must not be used with a y aesthetic.
And I need to include end date in chart.
raw data:
id1;2014-01-01;2014-02-01;town1
id1;2014-02-01;2014-04-01;town2
id2;2014-01-01;2014-02-01;town2
id2;2014-03-01;2014-05-01;town4
id3;2014-01-01;2015-02-01;town3