1

I have a sequence as follows

ts <- data.frame(seq.POSIXt(as.POSIXlt("2018-07-14 00:00"), as.POSIXlt("2018-07-16 13:52"), by="min"))
names(ts)[1]="Timestamp"
ts$Timestamp=format(ts$Timestamp, "%Y-%m-%d %H:%M")

values=rnorm(3713)

I am trying to generate a graph in r-bokeh such that the xaxis only displays the days (not the hours/minutes).

I have tried

   figure() %>% ly_lines(ts, values) %>% x_axis(label = "Date", format = list(months = "%Y-%m", days = "%d"))

But it hangs. I have also tried days="%Y-%m-%d" but no sucess either. Any thoughts on how I can generate a line plot for a time series, such that for the x-axis the formatting shows only the days rather than each minute. I am open to a ggplot solution as well.

Thanks!

FlyingPickle
  • 1,047
  • 1
  • 9
  • 19
  • 1
    First `rbind` into a data.frame: `df1 <- rbind(ts,values)`, then `df1 %>% ggplot(aes(Timestamp,values)) + geom_line()`, the default breaks are days. – Mako212 Aug 22 '18 at 23:01
  • 1
    Make sure `df1$Timestamp` is still of class POSIXct, otherwise assign it. – Mako212 Aug 22 '18 at 23:02

1 Answers1

0

Here you go!

library(tidyverse)

ts <- data.frame(seq.POSIXt(as.POSIXlt("2018-07-14 00:00"), as.POSIXlt("2018-07-16 13:52"), by="min"))
names(ts)[1]="Timestamp"
ts$Timestamp=format(ts$Timestamp, "%Y-%m-%d %H:%M")

values=rnorm(3713)

plot_df <- cbind(ts, values) %>% 
  mutate(time = as.POSIXct(Timestamp, format = "%Y-%m-%d %H:%M"))

plot_df %>% 
  ggplot(aes(x = time, y = values)) + 
  geom_line()

Your plot!

Vivek Katial
  • 543
  • 4
  • 17