How can I make a scatterplot matrix in R that shows only a subset of my data (in area A, B, C, or D, as opposed to all 4 aggregated)?
I know that the tapply() function allows for a breakdown by subset. For ex:
tapply(data$x, data$y, summary)
...would give me a statistics summary for each subset.
Here is my script for the scatterplot matrix. NEMSIS is my dataset name. I want to make a scatter plot of data from columns 2 through 5.
#Make scatterplot matrix using gclus package.
install.packages("gclus")
library(gclus)
matrix = NEMSIS[,2:5]
matrix.r = abs(cor(matrix))
matrix.col = dmat.color(matrix.r)
cpairs(matrix, panel.colors=matrix.col, gap=.5, main="Scatterplot Matrix of Times")
Any thoughts on how I can create a scatterplot matrix while incorporating the tapply() function to limit the plotted data to a subset? Thanks!
You can subset using typical methods for row subsetting; using
which()
is simple. For example, I want a scatterplot matrix of a few columns ofmtcars
, but I'm only interested in the rows wherecyl
is 4.