Haribo
Haribo

Reputation: 2226

plot each day of time series in a single plot in ggplot

I have one month of data as time series with 1 Hz sampling frequency :

data <- data.frame(
  date = as.POSIXct("2019-01-01 12:00:00") - 0:2678399,
  value = runif(2678400) + seq(-140, 224,len = 2678400)^2 / 10000
)

How could I use ggplot to have one plot per day?

Upvotes: 1

Views: 113

Answers (1)

Ali Hadjihoseini
Ali Hadjihoseini

Reputation: 951

library(dplyr)
data = data %>% group_by(day = cut(date, "day"))

ggplot(data, aes(date,value),show.legend = FALSE) + 
      geom_point() +
      facet_wrap(~day, ncol = 5, scales = "free_x)

Upvotes: 1

Related Questions