library(ggplot2)这段代码生成了一个漂亮的图:
qplot(cty, hwy, data = mpg, colour = displ) +
scale_y_log2() +
labs(x="x axis") +
labs(y="y axis") +
opts(title = "my title")但我想设置变量来尝试并减少代码重复:
log_scale <- scale_y_log2()
xscale <- labs(x="x axis")
yscale <- labs(y="y axis")
title <- opts(title = "my title")
my_scales <- c(log_scale, xscale, yscale, title)
# make a variable to hold the scale info changes above这样我就可以在做这件事的同时添加一堆东西:
qplot(cty, hwy, data = mpg, colour = displ) + my_scales
# add these to your plot. 但是我得到了这个错误:
Error in object$class : $ operator is invalid for atomic vectors我意识到进入my_scales的东西需要是层/不同类型的对象,但我看不出它们应该是什么。
发布于 2010-04-12 09:35:37
使用列表:
my_scales <- list(log_scale, xscale, yscale, title) https://stackoverflow.com/questions/2619400
复制相似问题