Learn R Programming

ggeasy (version 0.1.6)

easy_labs: Easily add ggplot labels using label attribute of `data.frame` column

Description

Applies same logic as labs but uses as default the column label attribute if present as the variable label in the plot. Note that as of ggplot2 3.5.2.9001 this behaviour is native and this function will be deprecated.

Usage

easy_labs(..., teach = FALSE)

Arguments

...

A list of new name-value pairs. The name should either be an aesthetic, or one of "title", "subtitle", or "caption"

teach

print longer equivalent ggplot2 expression?

Examples

Run this code
if (FALSE) {
iris_labs <- iris

lbl <- c('Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width', 'Flower Species')

labelled::var_label(iris_labs) <- split(lbl,names(iris_labs))

p <- ggplot2::ggplot(iris_labs,ggplot2::aes(x=Sepal.Length,y=Sepal.Width))+
  ggplot2::geom_line(ggplot2::aes(colour=Species))

p

p + easy_labs()
p + easy_labs(title = "Plot Title", subtitle = 'Plot Subtitle', x = 'x axis label')

p + easy_labs(teach = TRUE)
}

Run the code above in your browser using DataLab