[R] several car scatterplots on one graph

Greg Snow Greg.Snow at imail.org
Thu Oct 14 18:41:47 CEST 2010


The problem is that the scatterplot function is overriding the par(mfrow=c(2,2)) command by resetting the parameters itself (though it probably uses layout instead of par) to place the boxplots next to the scatterplot.  It was not really designed to be used the way you want.

Possible solutions:

Do it yourself, use the layout command to set up space for the scatterplots and boxplots, then plot them each individually using plot and boxplot commands.

Open 3 graphics devices and do a scatterplot in each one, then arrange the windows so you can see them all at once.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of cryan at binghamton.edu
> Sent: Wednesday, October 13, 2010 10:17 PM
> To: r-help at r-project.org
> Subject: [R] several car scatterplots on one graph
> 
> R version 2.11.1 on WinXP
> 
> How do I get 3 scatterplots with marginal boxplots (from the car
> package) onto a single plot?
> 
> I have a data frame called bank
> 
> > dim(bank)
> [1] 46  5
> 
> head(bank)
> 
>      x1    x2   x3   x4 pop
> 1 -0.45 -0.41 1.09 0.45   0
> 2 -0.56 -0.31 1.51 0.16   0
> 3  0.06  0.02 1.01 0.40   0
> 4 -0.07 -0.09 1.45 0.26   0
> 5 -0.10 -0.09 1.56 0.67   0
> 6 -0.14 -0.07 0.71 0.28   0
> 
> library(car)
> par(mfrow=c(2,2))
> 
> # following lines may be wrapped badly--sorry
> 
> with(bank, scatterplot(x1,x2,groups=pop, reg.line=FALSE,
> smooth=FALSE, boxplots="xy", reset.par=FALSE))
> 
> with(bank, scatterplot(x1,x3,groups=pop, reg.line=FALSE,
> smooth=FALSE, boxplots="xy", reset.par=FALSE))
> 
> with(bank, scatterplot(x1,x4,groups=pop, reg.line=FALSE,
> smooth=FALSE, boxplots="xy", reset.par=FALSE))
> 
> I have tried various permutations of the reset.par=  option: all
> three lines FALSE, all 3 lines TRUE, the first TRUE and the others
> FALSE, vice versa, etc. And always I get just one scatterplot showing
> up on the device at a time, and occupying the whole thing.
> 
> Thanks.
> 
> --Chris Ryan
> SUNY Upstate Medical University
> Binghamton Clinical Campus
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list