アドレッシング変数を名前の代わりに列番号で描画する必要があります。つまり、ggplot(dat, aes(x=Var1, y=Var2))
の代わりにggplot(dat, aes(x=dat[,1], y=dat[,2]))
のようなものが必要です。 (後者は機能しないので、私は「何か」と言う)。変数番号によるxとyのアドレッシング
は、ここに私のコードです:
showplot1<-function(indata, inx, iny){
dat<-indata
print(nrow(dat)); # this is just to show that object 'dat' is defined
p <- ggplot(dat, aes(x=dat[,inx], y=dat[,iny]))
p + geom_point(size=4, alpha = 0.5)
}
testdata<-data.frame(v1=rnorm(100), v2=rnorm(100), v3=rnorm(100), v4=rnorm(100), v5=rnorm(100))
showplot1(indata=testdata, inx=2, iny=3)
# Error in eval(expr, envir, enclos) : object 'dat' not found
確かに、あなたのソリューションはより柔軟に見える、私は正しい軸のタイトルを作ることも好きです...ありがとう! –
ggplot2 v2.0.0から:aes_q()はaes_()に置き換えられ、他のパッケージのNSE関数のSEバージョンと一致します。https://github.com/hadley/ggplot2/blob/master/NEWS.md#非難された機能 – Tung