R plot binary timeseries

plot, r

Solution

Is think this is what you want. Using fake data:

n = 100
x = seq(n)
y = sample(0:1, n, replace=TRUE)

DF = data.frame(Date=x, Event=y)

ones = rep(1, nrow(DF))

colors = c("blue", "red")
plot(DF$Date, ones, type="h", col=colors[DF$Event +1],
     ylim=c(0,1))

Problem

I have a dataset where I have a binary value on a timeline. So for example: ``` Date, Event January-29-2014, 1 January-29-2014, 0 January-29-2014, 1 January-29-2014, 1 January-30-2014, 0 ``` I would like to plot the 1,0 on a timeline(by Date) and in color (red bar = 1,blue bar = 0) How can I achieve this ? How do you call this ? e.g. binary timeline plotting :) Sorry and thanks for your help.

Original source