[R] muliple plots with pairs (matrix of scatter plots)
Landini Massimiliano
numero.primo at tele2.it
Tue Dec 21 11:51:37 CET 2004
On Tue, 21 Dec 2004 12:47:44 +1300, you wrote:
|=[:o) Hi
|=[:o)
|=[:o)
|=[:o) Uwe Ligges wrote:
|=[:o) > Tiago R Magalhaes wrote:
|=[:o) >
|=[:o) >> I am trying to make a graph with 4 scatter matrixes plots and couldn't
|=[:o) >> do it. While trying to find a solution for this I also came across the
|=[:o) >> idea of giving different values to the same argument for each of the
|=[:o) >> lower and upper function but couldn't do it. (Examplified below with
|=[:o) >> the col argument). The first problem of plotting 4 scatter matrixes in
|=[:o) >> a graph is a problem of real interest for me at this point. The second
|=[:o) >> problem is a matter of curiosity.
|=[:o) >>
|=[:o) >> I am using a Mac PowerBook G4 with OS 10.3.7 and R 2.0.1
|=[:o) >>
|=[:o) >>
|=[:o) >> Problem 1)
|=[:o) >> x=data.frame(a=sample(1:100, 50), b=sample(1:100, 50),c=sample(1:100,
|=[:o) >> 50),d=sample(1:100, 50))
|=[:o) >> x.list=vector('list',4)
|=[:o) >> for (j in 1:4) x.list[[j]]=x
|=[:o) >>
|=[:o) >> #produces a graph with four plots:
|=[:o) >> layout(matrix(c(1,3,2,4),2,2))
|=[:o) >> for (j in seq(x)){
|=[:o) >> plot(x.list[[j]][1:2])
|=[:o) >> }
|=[:o) >>
|=[:o) >> # But unfortunately the following produces a new plot everytime:
|=[:o) >> layout(matrix(c(1,3,2,4),2,2))
|=[:o) >> for (j in seq(x)){
par(new=TRUE)
|=[:o) >> pairs(x.list[[j]])
|=[:o) >> }
|=[:o) >> #Maybe pairs can't be used to produce a graph with multiple plots?
|=[:o) >
|=[:o) >
|=[:o) > Yes, it uses similar constructs to put multiple plots together.
|=[:o) >
|=[:o) > You might want to use packages grid and gridBase to set something up
|=[:o) > using viewports.
|=[:o)
|=[:o)
|=[:o)
|=[:o) I don't think that's going to work either -- pairs() makes some pretty
|=[:o) strong assumptions that it is the only plot on the page.
|=[:o)
|=[:o) One possible way to go is to use splom() instead from the lattice
|=[:o) package. For example (using your data from above) ...
|=[:o)
|=[:o) splom(~ x)
|=[:o)
|=[:o) ... and lattice plots can be embedded in grid viewports easily, for
|=[:o) example ...
|=[:o)
|=[:o) grid.newpage()
|=[:o) pushViewport(viewport(layout=grid.layout(2, 2)))
|=[:o) for (j in seq(x)) {
|=[:o) row <- (j - 1) %/% 2 + 1
|=[:o) col <- (j - 1) %% 2 + 1
|=[:o) pushViewport(viewport(layout.pos.col=col,
|=[:o) layout.pos.row=row))
|=[:o) print(splom(~ x.list[[j]]), newpage=FALSE)
|=[:o) popViewport()
|=[:o) }
|=[:o) popViewport()
|=[:o)
|=[:o) ... you may need to fiddle with the splom() args to get them looking how
|=[:o) you want them.
|=[:o)
|=[:o) Paul
-------------------------------------------------------------------------------------------------------------------------
Landini dr. Massimiliano
Tel. mob. (+39) 347 140 11 94
Tel./Fax. (+39) 051 762 196
e-mail: numero (dot) primo (at) tele2 (dot) it
-------------------------------------------------------------------------------------------------------------------------
Legge di Hanggi: Più stupida è la tua ricerca, più verrà letta e approvata.
Corollario alla Legge di Hanggi: Più importante è la tua ricerca, meno verrÃ
capita.
More information about the R-help
mailing list