1
votes

ggplot labels are typically added by the augument xlab/ylab, e.g.

 ggplot(mtcars,aes(mpg, wt)) + geom_point()+ xlab('x_label')+ ylab('y_label')

Is there any shortcut to predefine the label and call them? e.g.: mylabels is predefined . This would make repetitive use of certain labels more efficient.

mylabels <- xlab('x_label')+ylab('y_label') 
ggplot(mtcars,aes(mpg, wt)) + geom_point() + mylabels
1

1 Answers

5
votes

You could store the label information in a list as follows

mylabels <- list(
  xlab("x_label"), 
  ylab("y_label")
)
ggplot(mtcars,aes(mpg, wt)) + geom_point() + mylabels