Dear list-members, I wonder if there is a way of creating a scatter plot table/grid with different variables on the y-axis compared to the x-axis? Something like this: A*** B*** C*** -XYZ I know that you can create scatter plot matrix with the same variables on the y-axis as on the x-axis, like this: A***** *B**** **C*** ***X** ****Y* *****Z But this is not what I want. I basically want to get a visual representation of different dependent variables (y-axis) on various independent variables (x-axis). So I want it to look like a scatter plot matrix or grid, but with my own specified variables on each axis. Secondly, to add to this, can I add a correlation line (linear and quadratic) through all scatter plots with both correlation and R2 values? All help appreciated. Adel -- Adel Daoud, PhD Department of Sociology, University of Gothenburg Box 720 405 30 Göteborg, SWEDEN Visiting address: Sprängkullsgatan 25, room F411 +46 031-786 47 84 Adel.daoud@sociology.gu.se -- View this message in context: http://r.789695.n4.nabble.com/scatter-plot-matrix-with-different-x-y-variables-tp4666598.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Several ways but I find that grid.arrange in the gridExtra package combined with ggplot2 to draw the actual graphs works nicely. You might also want to look mfcol or mfrow in ?par ### quick and dirty example of ggplot2/gridExtra library(ggplot2) library(gridExtra) mdat <- data.frame(a= 1:5, b=1:5) ndat <- data.frame(x = rnorm(20), y = rnorm(20)) p <- ggplot(mdat , aes(a,b, colour = 'red' )) + geom_point() + theme(legend.position="none") p q <- ggplot(ndat , aes( x, y )) + geom_line() q grid.arrange(p, q) ### I imagine that you will need to install the ggplot2 and gridExtra packages. See ?install.packages for help John Kane Kingston ON Canada> -----Original Message----- > From: adeldaoud at gmail.com > Sent: Wed, 8 May 2013 09:49:25 -0700 (PDT) > To: r-help at r-project.org > Subject: [R] scatter plot matrix with different x-y variables > > Dear list-members, > > I wonder if there is a way of creating a scatter plot table/grid with > different variables on the y-axis compared to the x-axis? Something like > this: > > A*** > B*** > C*** > -XYZ > > > I know that you can create scatter plot matrix with the same variables on > the > y-axis as on the x-axis, like this: > > > > A***** > *B**** > **C*** > ***X** > ****Y* > *****Z > > But this is not what I want. I basically want to get a visual > representation of different dependent variables (y-axis) on various > independent variables (x-axis). So I want it to look like a scatter plot > matrix or grid, but with my own specified variables on each axis. > > Secondly, to add to this, can I add a correlation line (linear and > quadratic) > through all scatter plots with both correlation and R2 values? > > > All help appreciated. > > Adel > > -- > Adel Daoud, PhD > Department of Sociology, University of Gothenburg > Box 720 > 405 30 GC6teborg, SWEDEN > Visiting address: SprC$ngkullsgatan 25, room F411 > +46 031-786 47 84 > Adel.daoud at sociology.gu.se > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/scatter-plot-matrix-with-different-x-y-variables-tp4666598.html > Sent from the R help mailing list archive at Nabble.com. > [[alternative HTML version deleted]] > > ______________________________________________ > 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.____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
The pairs2 function in the TeachingDemos package does what you describe. You give it 2 matricies instead of just one and it creates the plots. On Wed, May 8, 2013 at 10:49 AM, Adel <adeldaoud@gmail.com> wrote:> Dear list-members, > > I wonder if there is a way of creating a scatter plot table/grid with > different variables on the y-axis compared to the x-axis? Something like > this: > > A*** > B*** > C*** > -XYZ > > > I know that you can create scatter plot matrix with the same variables on > the > y-axis as on the x-axis, like this: > > > > A***** > *B**** > **C*** > ***X** > ****Y* > *****Z > > But this is not what I want. I basically want to get a visual > representation of different dependent variables (y-axis) on various > independent variables (x-axis). So I want it to look like a scatter plot > matrix or grid, but with my own specified variables on each axis. > > Secondly, to add to this, can I add a correlation line (linear and > quadratic) > through all scatter plots with both correlation and R2 values? > > > All help appreciated. > > Adel > > -- > Adel Daoud, PhD > Department of Sociology, University of Gothenburg > Box 720 > 405 30 Göteborg, SWEDEN > Visiting address: Sprängkullsgatan 25, room F411 > +46 031-786 47 84 > Adel.daoud@sociology.gu.se > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/scatter-plot-matrix-with-different-x-y-variables-tp4666598.html > Sent from the R help mailing list archive at Nabble.com. > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@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. > >-- Gregory (Greg) L. Snow Ph.D. 538280@gmail.com [[alternative HTML version deleted]]