Tiago R Magalhaes
2004-Dec-20 01:04 UTC
[R] muliple plots with pairs (matrix of scatter plots)
I am trying to make a graph with 4 scatter matrixes plots and
couldn't do it. While trying to find a solution for this I also came
across the idea of giving different values to the same argument for
each of the lower and upper function but couldn't do it. (Examplified
below with the col argument). The first problem of plotting 4 scatter
matrixes in a graph is a problem of real interest for me at this
point. The second problem is a matter of curiosity.
I am using a Mac PowerBook G4 with OS 10.3.7 and R 2.0.1
Problem 1)
x=data.frame(a=sample(1:100, 50), b=sample(1:100, 50),c=sample(1:100,
50),d=sample(1:100, 50))
x.list=vector('list',4)
for (j in 1:4) x.list[[j]]=x
#produces a graph with four plots:
layout(matrix(c(1,3,2,4),2,2))
for (j in seq(x)){
plot(x.list[[j]][1:2])
}
# But unfortunately the following produces a new plot everytime:
layout(matrix(c(1,3,2,4),2,2))
for (j in seq(x)){
pairs(x.list[[j]])
}
#Maybe pairs can't be used to produce a graph with multiple plots?
Problem 2)
I wanted to plot upper and lower panels with different colours. I
tried what I thougth was obvious, giving the col argument inside of
each function:
pairs (x, lower.panel=points(x, col=2), upper.panel=points(x,
col=3))# only the diagonal is plotted
pairs (x, lower.panel=points(x), upper.panel=points(x)) #once again
only the diagonal is plotted
pairs (x, lower.panel=points, upper.panel=points) #both panels are
plotted, actually, this is simlar to pairs(x)
#Another little observation that I thought was strange:
pairs(x, lower.panel=points(x), col=2)# colours the outside box red
pairs(x, lower.panel=points(x), col=2, xaxt='n', yaxt='n')# does
what I want
pairs(x, lower.panel=points(x, col=2))# doesn't change the colour but
works otherwise
Thank you very much for any comments and help
[[alternative HTML version deleted]]
Tiago R Magalhaes wrote:> I am trying to make a graph with 4 scatter matrixes plots and > couldn't do it. While trying to find a solution for this I also came > across the idea of giving different values to the same argument for > each of the lower and upper function but couldn't do it. (Examplified > below with the col argument). The first problem of plotting 4 scatter > matrixes in a graph is a problem of real interest for me at this > point. The second problem is a matter of curiosity. > > I am using a Mac PowerBook G4 with OS 10.3.7 and R 2.0.1 > > > Problem 1) > x=data.frame(a=sample(1:100, 50), b=sample(1:100, 50),c=sample(1:100, > 50),d=sample(1:100, 50)) > x.list=vector('list',4) > for (j in 1:4) x.list[[j]]=x > > #produces a graph with four plots: > layout(matrix(c(1,3,2,4),2,2)) > for (j in seq(x)){ > plot(x.list[[j]][1:2]) > } > > # But unfortunately the following produces a new plot everytime: > layout(matrix(c(1,3,2,4),2,2)) > for (j in seq(x)){ > pairs(x.list[[j]]) > } > #Maybe pairs can't be used to produce a graph with multiple plots?Yes, it uses similar constructs to put multiple plots together. You might want to use packages grid and gridBase to set something up using viewports.> Problem 2) > I wanted to plot upper and lower panels with different colours. I > tried what I thougth was obvious, giving the col argument inside of > each function: > pairs (x, lower.panel=points(x, col=2), upper.panel=points(x, > col=3))# only the diagonal is plotted > pairs (x, lower.panel=points(x), upper.panel=points(x)) #once again > only the diagonal is plotted > pairs (x, lower.panel=points, upper.panel=points) #both panels are > plotted, actually, this is simlar to pairs(x) > > #Another little observation that I thought was strange: > pairs(x, lower.panel=points(x), col=2)# colours the outside box red > pairs(x, lower.panel=points(x), col=2, xaxt='n', yaxt='n')# does what I want > pairs(x, lower.panel=points(x, col=2))# doesn't change the colour but > works otherwiseYou have to specify a function, e.g. an unnamed one such as function(x, y) points(x, y, col=2) rather than a function call such as just points(x) Hence we get: pairs(x, lower.panel = function(x, y) points(x, y, col=2), upper.panel = function(x, y) points(x, y, col=3)) Uwe Ligges> Thank you very much for any comments and help > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Apparently Analagous Threads
- How to save R "clean" sessions in BATCH mode?
- pairs: altering pch options on upper and lower panel of pairwise scatter plots
- 3D scatter plot with projections
- Passing Muliple Parameters with remote_function
- Muliple SQL statements / Return percentage of rows