Reputation: 1133
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!
Upvotes: 1
Views: 332
Reputation: 626
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()
Upvotes: 0