ggplot中轴标签的快捷方式

Sib*_*ang 1 r ggplot2 axis-labels

ggplot标签通常由augument xlab/ylab添加,例如

 ggplot(mtcars,aes(mpg, wt)) + geom_point()+ xlab('x_label')+ ylab('y_label')
Run Code Online (Sandbox Code Playgroud)

有预定义标签并调用它们的快捷方式吗?例如:mylabels是预定义的.这将使某些标签的重复使用更有效.

mylabels <- xlab('x_label')+ylab('y_label') 
ggplot(mtcars,aes(mpg, wt)) + geom_point() + mylabels
Run Code Online (Sandbox Code Playgroud)

小智 5

您可以将标签信息存储在列表中,如下所示

mylabels <- list(
  xlab("x_label"), 
  ylab("y_label")
)
ggplot(mtcars,aes(mpg, wt)) + geom_point() + mylabels
Run Code Online (Sandbox Code Playgroud)