Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Modifying date labels for facet_calendar in ggplot

I have a problem that I can’t solve on my own, despite searching for a solution for a long time.

I prepare a chart from data and use facet_calendar.

df1 <- read.table(text = "DT   odczyt.1 odczyt.2
'2023-08-14 00:00:00'   362 1.5
'2023-08-14 23:00:00'   633 4.3
'2023-08-15 05:00:00'   224 1.6
'2023-08-15 23:00:00'   445 5.6
'2023-08-16 00:00:00'   182 1.5
'2023-08-16 23:00:00'   493 4.3
'2023-08-17 05:00:00'   434 1.6
'2023-08-17 23:00:00'   485 5.6
'2023-08-18 00:00:00'   686 1.5
'2023-08-18 23:00:00'   487 6.8
'2023-08-19 00:00:00'   566 1.5
'2023-08-19 05:00:00'   278 7.9
'2023-08-19 17:00:00'   561 11.5
'2023-08-19 18:00:00'   365 8.5
'2023-08-19 22:00:00'   170 1.8
'2023-08-19 23:00:00'   456 6.6
'2023-08-20 00:00:00'   498 1.5
'2023-08-20 03:00:00'   961 1.54
'2023-08-20 05:00:00'   397 1.6
'2023-08-20 19:00:00'   532 6.6
'2023-08-20 23:00:00'   493 3.8
'2023-08-21 01:00:00'   441 9.2
'2023-08-21 07:00:00'   793 8.5
'2023-08-21 13:00:00'   395 5.5", header = TRUE) %>% 
  mutate (
    DT = as.POSIXct(DT),
    Rok = year (DT),
    Msc = month (DT),
    Godz = hour (DT),
    Dzien = day (DT),
    Date = as.Date (paste0 (Rok, "-", Msc, "-", Dzien))
          )

ggplot (df1 %>% filter (Rok == 2023 & Msc == 8)) +
  geom_col (aes (x = Godz, y = odczyt.1)) +
  facet_calendar(~Date)

The actual data is more complicated and includes data from many years.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

I would like to be able to control labels and set the month name to be presented as a full name (currently it is a 3-letter abbreviation)

>Solution :

Assuming you are using the facet_calendar function from the sugrrants package, if you check the ?facet_calendar help page, you’ll see it offers a format= parameter. To get the full month name use

facet_calendar(~Date, format="%B %d")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading