2016-08-12 68 views
-1

嘗試使用Deducercor.matrix創建ggcorplot中要使用的相關矩陣。在cor.matrix中指定變量

試圖運行一個簡單的例子。只有在數據工作中明確指定變量名稱:

cor.mat<-cor.matrix(variables=d(Sepal.Length,Sepal.Width,Petal.Length,Petal.Width), 
         data=iris[1:4],test=cor.test,method='p') 

但我希望它能夠簡單地使用提供的數據中的所有列。

此:

cor.mat<-cor.matrix(data=iris[1:4],test=cor.test,method='p') 

拋出一個錯誤:

Error in eval(expr, envir, enclos) : argument is missing, with no default 

此:

cor.mat<-cor.matrix(variables=d(as.name(paste(colnames(iris)[1:4]),collapse=",")), 
        data=iris[1:4],test=cor.test,method='p') 

Error in as.name(paste(colnames(iris)[1:4]), collapse = ",") : 
    unused argument (collapse = ",") 

那麼,有沒有辦法告訴variables使用的所有列在data沒有明確指定他們?

回答

0

函數的第一個參數是variables =,這是必需的,但您沒有指定(您有data =)。嘗試

cor.mat <- cor.matrix(variables = iris[1:4], test = cor.test, method = 'p') 
ggcorplot(cor.mat, data=iris) 

enter image description here

+0

@丹沒有這個解決您的問題?如果是這樣,請考慮upvoting /接受答案。 – dww