Learn R Programming

SimNPH (version 0.5.7)

labs_from_labels: Add ggplot axis labels from labels attribute

Description

Add ggplot axis labels from labels attribute

Usage

labs_from_labels(gg)

Value

a ggplot object

Arguments

gg

a ggplot object

Examples

Run this code
# \donttest{
library("ggplot2")
test <- mtcars
# add a label attribute
attr(test$cyl, "label") <- "cylinders"

# plot witht the variable names as axis titles
gg1 <- ggplot(test, aes(x=wt, y=cyl)) +
  geom_point()
gg1

# add labels where defined in the attribute
gg2 <- ggplot(test, aes(x=wt, y=cyl)) +
  geom_point()

gg2 <- labs_from_labels(gg2)
gg2
# }

Run the code above in your browser using DataLab