Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R plot binary timeseries

Tags:

plot

r

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.

like image 250
digit Avatar asked Nov 02 '22 06:11

digit


1 Answers

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))

theplot

like image 166
Ricardo Oliveros-Ramos Avatar answered Nov 08 '22 05:11

Ricardo Oliveros-Ramos