# copy mtcars to df
# create a data set
df <- mtcars
# variable names and their labels
names_labs_vec <- c(
"mpg" = "Miles/(US) gallon",
"cyl" = "Number of cylinders",
"wt" = "Weight (1000 lbs)"
)
df <- add_name_labs(df, name.labs = names_labs_vec)
# ggplot example of axis_lab()
library(ggplot2)
p <- ggplot(df, aes(mpg, wt, color = cyl)) +
geom_point()
p <- p +
labs(color = axis_lab(df, cyl)) +
xlab(axis_lab(df, mpg)) +
ylab(axis_lab(df, wt))
# Base R plot example (using alb() alias)
with(df, plot(mpg, wt,
xlab = alb(df, mpg),
ylab = alb(df, wt)
))
Run the code above in your browser using DataLab