简体   繁体   中英

How to use pairs.panel for only certain rows in the dataframe in R

I am trying to create a correlation panel using only specific rows. I am using the native R dataframe "iris" and want to create three correlation panels that relate only to particular species. This is my code:

library(psych)
pairs.panels(iris[iris$Species == "setosa",], lm=TRUE)
pairs.panels(iris[iris$Species == "versicolor",], lm=TRUE)
pairs.panels(iris[iris$Species == "virginica",], lm=TRUE)

Although I am getting a correlation panel for each specie separately, I keep getting this error:

Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) : 'a' and 'b' must be finite 

This is the error that appears on the correlation panel output (pls see link): error on panel

I already tried creating different dataframes that only contain the specific rows that I want. For example:

setosa <- iris[iris$Species == "setosa",]
pairs.panels(setosa, lm=TRUE)

But I still get the same error.

Would appreciate any help to try and get rid of the error.

You can also use the factor to give colors to scatterplot, as in the example

pairs.panels(iris[, c(1:4)], #never include factors in corr matrix
             bg=c("blue4","pink",'darkgreen')[iris$Species],#use factor to give colors to scatterplots
             pch=21,
             lm=TRUE, 
             method='kendall')

带系数的corr矩阵

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM