How to deal with hourly data in r

Hi, I am now handling the hourly data in RStudio which is from 2018 and 2022 and the date of my data is like 01/01/2018 HOUR1, 01/01/2018 HOUR2. 01/01/2018 HOUR3 and so on. I would like to ask if I want to plot a boxplot in r, then is it I need to convert my data into yearly data? If I would like to do so, how can I do it? Thanks.

Hi, welcome!

We don't really have enough info to help you out. Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

If you've never heard of a reprex before, you might want to start by reading this FAQ:

1 Like

Generally speaking, if you had a data table resembling the one I have created below, then you could create a box plot for each hour.

library(tidyverse)

# create sample data
set.seed(234)
(sample_data <- tibble(
  id = seq(1, 100, 1),
  value = rnorm(n = 100, mean = 50, sd = 5),
  date_time = sample(
    seq(ymd_hms("2000-01-01 00:00:01"), ymd_hms("2001-12-31 23:59:59"), 1), 
    size = 100, 
    replace = TRUE)
))
#> # A tibble: 100 × 3
#>       id value date_time          
#>    <dbl> <dbl> <dttm>             
#>  1     1  53.3 2001-10-07 17:43:52
#>  2     2  39.7 2001-12-28 14:13:51
#>  3     3  42.5 2001-04-26 03:33:53
#>  4     4  57.4 2000-12-23 00:36:11
#>  5     5  57.3 2001-09-07 09:27:33
#>  6     6  50.7 2000-12-09 04:38:09
#>  7     7  51.0 2000-08-02 15:33:13
#>  8     8  34.8 2000-06-22 20:12:39
#>  9     9  47.6 2001-10-02 14:31:58
#> 10    10  44.6 2001-01-17 06:22:01
#> # ℹ 90 more rows

# boxplot of value for each hour
sample_data %>%
  mutate(
    hourly = hour(date_time)
  ) %>%
  ggplot() +
  geom_boxplot(
    mapping = aes(
      group = hourly,
      x = hourly,
      y = value
    )
  ) +
  ylim(0, NA)

Created on 2024-02-13 with reprex v2.0.2