[R] Scatterplot of many variables against a single variable

MacQueen, Don macqueen1 at llnl.gov
Mon Nov 27 20:08:27 CET 2017

Here's the quickest way I know of to get a scatterplot of many variables against a single variable. I create example data to illustrate.

x <- 1:10
ys <- matrix( runif(30), ncol=3)

## or, a little better,
matplot(x,ys, type='b')

To add regression lines:

for (iy in seq(ncol(ys))) abline(lsfit(x, ys[,iy]))

Coloring the regression lines to match the matplot will take a little more work (but not a lot more).

Don't ask me about putting the regression line formulas on the plot like in Excel. I don't do things that way...

There is probably something in ggplot2 or some other package.


Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
Lab cell 925-724-7509

On 11/27/17, 12:56 AM, "R-help on behalf of Engin YILMAZ" <r-help-bounces at r-project.org on behalf of ispanyolcom at gmail.com> wrote:

    I try to realize one scatter matrix which draws *one single variable to all
    variables* with *regression line* . You can see my eviews version  in the
    annex .
    How can I draw this graph with R studio?
    Engin YILMAZ
    R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
    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