Наносящие пары участвуют на основе условия

StackOverflow https://stackoverflow.com/questions/5057060

  •  15-11-2019
  •  | 
  •  

Вопрос

** Редактировать: ** Я прошу прощения, но ситуация может быть немного сложнее, чем я показал.Тем не менее, обе ваши сценарии работают, хотя первым может быть не так понятно для большого набора данных из-за перекрытия точки!Большое спасибо Sacha!

Я хотел бы сначала показать пары нескольких переменных, а затем нанося выбирать данные одинакового набора данных.Обычно накладки могут быть достигнуты с использованием генеракодицетагкода, как это:

h<-rnorm(nc)  # this variable was used for conditioning
x<-rnorm(nc)
y<-rnorm(nc)
z<-rnorm(nc)
m<-cbind(x,y,z)
pairs(m)
par(new=T)
pairs(m[h>0.7,],col="red")
.

Однако, кажется, настройка GenSodicEtagcode не работает для такого использования.

Тогда, вероятно, библиотека решетки может помочь, например.Генеракодицетагкод, но я не знаю, действительно ли это работает и как.Может кто-то дать несколько предложений?

Это было полезно?

Решение

I assume paris must be pairs? The pairs function doesn't have an add argument or so, it would probably also not be that trivial since the plot has 9 panels (simply doing points will plot in the last panel). but it is not that hard to do what you want in a single plot using col:

nc <- 100
set.seed(1)
x<-rnorm(nc)
y<-rnorm(nc)
z<-rnorm(nc)
m<-cbind(x,y,z)

cols <- ifelse(x>0.7,"red","black")
pairs(m,col=cols)

enter image description here

Edit:

Another thing you can do in pairs is actually set the function you want to do in each panel. By default this is points, but you can extend that to include some conditions:

nc <- 100

X<-rnorm(nc)
Y<-rnorm(nc)
Z<-rnorm(nc)
m<-cbind(X,Y,Z)

panelfun <- function(x,y,foo=X,...){
    points(x[foo<0.7],y[foo<0.7],col="black",...)
    points(x[foo>0.7],y[foo>0.7],col="red",...)
}

pairs(m,panel=panelfun)

This gives the same picture as before (well different points because I didnt set a seed). Simply making the color vector would be easier to accomplish this, but you can make the panel function as big as you would like.

Also, the ... allow other arguments to be passed to the points function:

pairs(m,panel=panelfun,pch=16)

Другие советы

lattice::splom works fine. The color indexing needs to be boosted by 1 since R indexing is 1 based rather than zero-based and the logical vectors get coerced as 0 and 1.

library(lttice)
nc=100; h<-rnorm(nc)  
x<-rnorm(nc)
y<-rnorm(nc)
z<-rnorm(nc)
m<-cbind(x,y,z)
splom(m, col=c("blue", "red")[1+(h>0.7)])

enter image description here

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top