简体   繁体   English

如何仅对R中数据框中的某些行使用pairs.panel

[英]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. 我正在使用本地R数据框“ iris”,并希望创建三个仅与特定物种相关的关联面板。 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矩阵

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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