r - plotting data with a series of start end dates -


how go plotting data series of start end date bands?

i have dataframe looks like:

start<-as.posixct(c("2017-07-13 01:40:00 mdt", "2017-07-21 06:00:00 mdt", "2017-07-21 14:00:00 mdt", "2017-07-24 11:00:00 mdt",         "2017-07-24 12:00:00 mdt", "2017-07-25 05:00:00 mdt", "2017-07-25 17:00:00 mdt", "2017-07-26 12:00:00 mdt",         "2017-07-30 12:00:00 mdt", "2017-07-31 04:00:00 mdt", "2017-07-31 15:00:00 mdt", "2017-08-03 18:30:00 mdt",         "2017-08-03 23:30:00 mdt", "2017-08-09 05:00:00 mdt", "2017-08-09 20:00:00 mdt", "2017-08-14 09:00:00 mdt",         "2017-08-16 05:00:00 mdt", "2017-08-16 07:00:00 mdt", "2017-08-16 19:00:00 mdt", "2017-08-17 18:00:00 mdt",         "2017-08-20 05:00:00 mdt", "2017-08-23 06:00:00 mdt", "2017-08-23 14:00:00 mdt", "2017-08-24 17:00:00 mdt",         "2017-08-28 00:00:00 mdt"))  end<-as.posixct(c("2017-07-21 06:00:00 mdt", "2017-07-21 14:00:00 mdt", "2017-07-24 11:00:00 mdt", "2017-07-24 12:00:00 mdt",     "2017-07-25 05:00:00 mdt", "2017-07-25 17:00:00 mdt", "2017-07-26 12:00:00 mdt", "2017-07-30 12:00:00 mdt",     "2017-07-31 04:00:00 mdt", "2017-07-31 15:00:00 mdt", "2017-08-03 18:30:00 mdt", "2017-08-03 23:30:00 mdt",     "2017-08-09 05:00:00 mdt", "2017-08-09 20:00:00 mdt", "2017-08-14 09:00:00 mdt", "2017-08-16 05:00:00 mdt",     "2017-08-16 07:00:00 mdt", "2017-08-16 19:00:00 mdt", "2017-08-17 18:00:00 mdt", "2017-08-20 05:00:00 mdt",     "2017-08-23 06:00:00 mdt", "2017-08-23 14:00:00 mdt", "2017-08-24 17:00:00 mdt", "2017-08-28 00:00:00 mdt",     "2017-09-28 13:00:00 mdt"))  rate<-c(1485, 0, 1485,  880, 1485, 0, 1485, 1100, 1485, 0, 1485, 1483, 1485, 0, 1485, 1419, 880, 0, 1419, 1485, 1419, 0, 1100, 419, 1100)  df<-data.frame(start, end, rate) 

i plot 'rate' on y-axis , dates on x-axis. there method go doing in ggplot or plotting package?

note: end date when next rate starts. also, line chart.

i think it...

library(ggplot2) ggplot(df)+     geom_rect(aes(xmin=as.posixct(as.character(start)),                   xmax=as.posixct(as.character(end)),                   ymin=0,                   ymax=rate)) 

enter image description here

alternatively, line plot, try

ggplot(df)+     geom_segment(aes(x=as.posixct(as.character(start)),                      xend=as.posixct(as.character(end)),                      y=rate,                      yend=rate), size=2) 

enter image description here


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -