最佳答案
我试图将列索引传递给 ggplot,作为我将重复使用的函数的一部分。 例如:
myplot <- function(df){
ggplot(df, aes(df[, 1], df[, 2])) + geom_point()
}
I'll always be using the first column as my x variable and the second column as my y-variable, but the column names change between data sets. I've searched all over.. Any ideas?
这是我的回答:
require(ggplot2)
myplot <- function(df){
ggplot(df, aes_string(colnames(df)[1], colnames(df)[2])) + geom_point()
}