我正在尝试在
现在我想使用变量传递
我使用以下公式,应该等同于上面的
ggplot2
中运行此代码,它可以完美地运行。p <- ggplot(diamonds, aes(x= depth , y = price), color = cut))
p + geom_point()
现在我想使用变量传递
x
和y
,以便我可以在for循环中使用它们。var1 <- colnames(diamonds)
var1
是一个向量,包含以下变量:
[1] "carat" "cut" "color" "clarity" "depth" "table"
[7] "price" "x" "y" "z"
我使用以下公式,应该等同于上面的
ggplot2
。p <- ggplot(diamonds, aes(x= var1[5] , y = var1[7]), color = cut))
p + geom_point()
这一次,var1[5]
被视为一个变量,var1[7]
也被视为另一个变量,而不是它们被解析成深度和价格。
有没有什么方法可以解决这个问题。我已经使用了paste函数,但似乎没有起作用。
aes_string
函数。 - Rorschach