month_label_cat_esp: Add date labels in catalan or spanish to ggplot2

View source: R/month_label_cat_esp.r

month_label_cat_espR Documentation

Add date labels in catalan or spanish to ggplot2

Description

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

Usage

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

Arguments

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.

Value

A character vector or a ScaleContinuousDate object for a ggplot.

Examples

library(dply);library(ggplot2)
## 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) )
## plot
plot_1 <- ggplot(df1, aes(x,y))+ geom_line()

## catalan monthly labels
plot_1 +
    scale_x_date(breaks = '3 month', # specify step width
                 labels = month_label_cat_esp )

##  catalan monthly labels without abbreviate
plot_1 +
    scale_x_date(breaks = '3 month',
                 labels = ~ month_label_cat_esp(.x, abbr = FALSE ) )

## 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)) )

## 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) )

## extract a character vector of labels

ksnet::month_label_cat_esp( df2$z, language = 'spanish' )


octmedina/ksnet documentation built on April 18, 2023, 3:34 p.m.