I have a matrix mat[n,m]
and I'd like to use splom to plot the scatterplots of mat[,"col4"]
as a function of all other column values. Also I'd like to add different colors to points of certain row numbers which are stored in rownID[]
. I've seen examples using splom but they plot all variables against all variables and use group of columns to change the color of points. Is it possible to do what I want using splom (or other R function)?
Example:
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)
Thanks to https://stackoverflow.com/a/16033003/1262767
I've been using featurePlot function of caret package but I don't know how to change color of some specific points (that's why I'm interested in 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"))
This doesn't really seem like a good fit for splom
. I think you're be better off reshaping your data and using a standard xyplot
. For example
library(reshape2)
mm<-melt(cbind(data.frame(mat), high=1:nrow(mat) %in% rowID), c("col4","high"))
xyplot(col4~value|variable, mm, groups=high)
which gives
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.