plot - How to implement a timeline in R with start date, end date, and a marker for a "middle date"? -




we have data frame in r of following format:

type    request id  event name  first seen           update       last seen          1          event1    1/29/2017 19:54 4/19/2017 14:16 4/19/2017 15:05                  2          event2    2/13/2017 14:20 5/2/2017 12:48  5/2/2017 12:54          3          event3    4/29/2017 16:30 5/12/2017 11:05 5/12/2017 12:08 b          4          event4    5/17/2017 20:23 5/18/2017 12:46 5/18/2017 16:15 

the corresponding csv file is:

type,request id,event name,first seen,update,last seen a,1,event1,1/29/2017 19:54,4/19/2017 14:16,4/19/2017 15:05 a,2,event2,2/13/2017 14:20,5/2/2017 12:48,5/2/2017 12:54 a,3,event3,4/29/2017 16:30,5/12/2017 11:05,5/12/2017 12:08 b,4,event4,5/17/2017 20:23,5/18/2017 12:46,5/18/2017 16:15 

we want visualize each instance on r timeline such can see event on timeline start date, update, , end date.

we able close our implementation in r goes this:

install.packages("timevis") library("timevis")  df <- read.csv("data.csv", header = true) df_new = rename(df, start = first.seen, end = last.seen, content = request.id) timevis(dataframe_new) 

note using 'start' date , 'end' date in implementation. plots following timeline:

enter image description here

now want incorporate 'update' date , time in there somehow such shown pointer in each bar or slab indicating update date , time. bar start @ start date, end @ end date, , have marker @ appropriate location show 'update'.

how can implement in r?

your data

df <- structure(list(type = c("a", "a", "a", "b"), request.id = 1:4,  event.name = c("event1", "event2", "event3", "event4"), first.seen = structure(c(1485719640,  1486995600, 1493483400, 1495052580), tzone = "utc", class = c("posixct",  "posixt")), update = structure(c(1492611360, 1493729280,  1494587100, 1495111560), tzone = "utc", class = c("posixct",  "posixt")), last.seen = structure(c(1492614300, 1493729640,  1494590880, 1495124100), tzone = "utc", class = c("posixct",  "posixt"))), class = "data.frame", .names = c("type", "request.id",  "event.name", "first.seen", "update", "last.seen"), row.names = c(na,  -4l)) 

tidyverse solution

i melt first.seen & update single column. last.seen values each update value = na (made singularity). add type column specifying point singularities , background ranges (to overlap values). add group value.

library(tidyverse) library(reshape2) library(lubridate) df1 <- df %>%           nest(first.seen, update) %>%           mutate(data = map(data, ~melt(.x))) %>%           unnest() %>%          mutate(last.seen = ifelse(variable == "update", as.character(na), as.character(last.seen))) %>%          mutate(last.seen = ymd_hms(last.seen)) %>%          mutate(type = ifelse(is.na(last.seen), "point", "background")) %>%          mutate(group = request.id) %>%          rename(start = value, end = last.seen, content = request.id) 

first 4 rows of df1

   type content event.name                 end   variable               start       type group 1           1     event1 2017-04-19 15:05:00 first.seen 2017-01-29 19:54:00 background     1 2           1     event1                  na     update 2017-04-19 14:16:00      point     1 3           2     event2 2017-05-02 12:54:00 first.seen 2017-02-13 14:20:00 background     2 4           2     event2                  na     update 2017-05-02 12:48:00      point     2 

specify groups , label each row groups=...

timevis(data=df1, groups=data.frame(id=unique(df1$group), content=letters[unique(df1$content)])) 

this produces 4 rows of timelines update singularity (point) marking each range of first.seen & last.seen.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -