Ir al contenido

Converting English default date labels to calatan or spanish ones in ggplots. #'

Uso

month_label_cat_esp(
  breaks,
  language = c("catalan", "spanish"),
  with_days = FALSE,
  abbr = TRUE
)

Argumentos

breaks

This argument is specified inside scale_x_date. See Examples.

language

Either 'catalan' or 'spanish'. By default catalan is selected.

with_days

Logical. If TRUE days are shown in the labels. By default is FALSE.

abbr

Logical. If TRUE full month labels are displayed. By default is FALSE.

Valor

A character vector or a ScaleContinuousDate object for a ggplot.

Ejemplos

library(dply);library(ggplot2)
#> Error in library(dply): there is no package called ‘dply’
## monthly sequence:
df1 <- data.frame(
    x = seq.Date(lubridate::as_date('2020-01-01'),lubridate::as_date('2022-05-01'),
                 by = '1 month'),
    y = rnorm(29) )
#> Error in loadNamespace(x): there is no package called ‘lubridate’
## plot
plot_1 <- ggplot(df1, aes(x,y))+ geom_line()
#> Error in ggplot(df1, aes(x, y)): objeto 'df1' no encontrado

## catalan monthly labels
plot_1 +
    scale_x_date(breaks = '3 month', # specify step width
                 labels = month_label_cat_esp )
#> Error in eval(expr, envir, enclos): objeto 'plot_1' no encontrado

##  catalan monthly labels without abbreviate
plot_1 +
    scale_x_date(breaks = '3 month',
                 labels = ~ month_label_cat_esp(.x, abbr = FALSE ) )
#> Error in eval(expr, envir, enclos): objeto 'plot_1' no encontrado

## daily sequence:
df2 <- tibble(
    'z' = seq.Date(lubridate::as_date('2021-12-01'),lubridate::as_date('2022-01-15'),
                                  by = '1 day'),
    y= runif(length(z)) )
#> Error in loadNamespace(x): there is no package called ‘lubridate’

## spanish daily labels
ggplot(df2, aes(z,y))+
    geom_line()+
    scale_x_date(breaks = '3 days', # specify step width
                 labels = ~ month_label_cat_esp(.x,language = 'spanish',
                                                with_days = TRUE) )
#> Error in ggplot(df2, aes(z, y)): objeto 'df2' no encontrado

## extract a character vector of labels

ksnet::month_label_cat_esp( df2$z, language = 'spanish' )
#> Error in data.frame(fecha = breaks): objeto 'df2' no encontrado