I need to put the min date value and the max date value in ggplot subtitle.

I've found a similar question but for the axis labels, I need to apply this to the subtitle argument:

subtitle = paste0("Del ", vitocho_likes_min_date, " al ", vitocho_likes_max_date)

Min date looks like:

"2010-10-14" #Expect: "14 de octubre del 2010"

dput(vitocho_likes_min_date)
structure(14896, class = "Date")

Max date looks like:

"2019-04-29" #Expect: "29 de abril del 2019"

dput(vitocho_likes_max_date)
structure(18015, class = "Date")

This is my ggplot chart:

vitocho_chart <- t_kids_faves %>%
  filter(user == "VictorAndresGB") %>%
  ggplot(aes(x = fct_reorder(screen_name, n), y = n)) +
  geom_col(fill = "#494A4F") +
  coord_flip() +
  theme_tweets() +
  labs(
    x = "",
    y = "",
    title = "Cuentas de Twitter con más likes de Victor Andrés García Belaunde.",
    subtitle = paste0("Del ", vitocho_likes_min_date, " al ", vitocho_likes_max_date)
  ) +
  geom_text(
    aes(x = screen_name,
        y = n - 15,
        label = n
    ),
    size = 4,
    color = "gray95"
  )

1 Answers

1
captcoma On Best Solutions

use:

Sys.setlocale("LC_TIME", "Spanish") 
vitocho_likes_min_date= as.character(format(as.Date(14896, origin="1970-01-01"), "%d de %B del %Y"))
vitocho_likes_max_date= as.character(format(as.Date(18015, origin="1970-01-01"), "%d de %B del %Y"))