datetime - r: How to print a histogram of daytimes with times in Format e.g. 13:00 in ggvis -


i have data.frame datetime objects, read in csv file , turned datetime objects dmy_hm() lubridate package. want print histogram distribution of times, independent of date. here example, looks pretty good:

library(dplyr) library(ggvis) library(lubridate)  # create example gespeichert <- c(rep("01/05/2016 15:26",times=10),                  rep("13/05/2016 00:17",times=5),                  rep("01/08/2016 12:05",times=10),                  rep("17/04/1983 23:39",times=5),                  rep("06/07/2015 09:36",times=10)) info <- c(rep("bla",times=30),rep("bla bla",times=10))  df_time <- cbind.data.frame(gespeichert,info,stringsasfactors=false)            df_time %>%   mutate(gespeichert = dmy_hm(gespeichert)) -> df_time  # trying reduce datetime object time df_time %>%   mutate(uhrz_num = hour(gespeichert) * 60 + minute(gespeichert)) %>% # time in minute numbers, not necessary   mutate(gesp_uhrzeit = format(gespeichert,format="%h:%m")) %>%  # http://stackoverflow.com/questions/9839343/extracting-time-from-posixct   mutate(gesp_uhrzeit = as.posixct(gesp_uhrzeit,format="%h:%m")) -> df_time                # plot                df_time %>%     ggvis(x=~gesp_uhrzeit) %>%      layer_histograms() %>%      scale_datetime("x", nice = "minute",label="daytime") 

histogram daytimes ggvis

i have 2 problems here x-axis:

  1. i want x-axis show times in form of e.g. 15:00 not 03pm

  2. at both sides shows todays date , date of next day, because in code delete date mutate(gesp_uhrzeit = format(gespeichert,format="%h:%m")) takes todays date date. how can rid of that? (can create time object? can convert numbers still show time?)

if can give me tips appreciated. alternative packages, changing data structure, every idea welcome.

additional question: if knows how make binwidth interactive (in case!), please tell me. not necessary, nice feature me. did in cases there numbers, not successful datetime objects.

just add add_axis right format code pipe:

> df_time %>%      ggvis(x=~gesp_uhrzeit) %>%       layer_histograms() %>%       scale_datetime("x", nice = "minute",label="daytime") %>%      add_axis(type="x",format="%h:%m") 

this give plot hour:minute times, , not show days.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -