散点图矩阵

时间:2014-09-15 14:04:14

标签: r scatter-plot

我有一个矩阵mat[n,m],我想使用 splom 绘制mat[,"col4"]的散点图作为所有其他列值的函数。另外,我想为rownID[]中存储的某些行号添加不同的颜色。我已经看过使用 splom 的示例,但是它们针对所有变量绘制所有变量,并使用列组来更改点的颜色。是否可以使用 splom (或其他R功能)做我想做的事情?

示例:

set.seed(1)
mat <-  matrix(sample(0:100, 16), ncol=4)

dimnames(mat) <- list(rownames(mat, do.NULL = FALSE, prefix = "row"),
                          colnames(mat, do.NULL = FALSE, prefix = "col"))

mat
     col1 col2 col3 col4
row1   26   19   58   61
row2   37   86    5   33
row3   56   97   18   66
row4   89   62   15   42

rowID <- matrix(c(1,3), ncol=1, nrow=2)

感谢https://stackoverflow.com/a/16033003/1262767

我一直在使用插入包的 featurePlot 功能,但我不知道如何更改某些特定点的颜色(&#39;为什么我对 splom )感兴趣:

featurePlot(mat, mat$col4, plot = "scatter",
            ## Add some space between the panels
            between = list(x = 1, y = 1), main = "testSet",
            ## Add a background grid ('g') and a smoother ('smooth')
            type = c("g", "p", "s"))

1 个答案:

答案 0 :(得分:1)

这似乎不适合splom。我认为您最好重新塑造数据并使用标准xyplot。例如

library(reshape2)
mm<-melt(cbind(data.frame(mat), high=1:nrow(mat) %in% rowID), c("col4","high"))
xyplot(col4~value|variable, mm, groups=high)

给出了

enter image description here

相关问题