Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

5. Scatter Plots > Making a Scatter Plot Matrix

Making a Scatter Plot Matrix

Problem

You want to make a scatter plot matrix.

Solution

A scatter plot matrix is an excellent way of visualizing the pairwise relationships among several variables. To make one, use the pairs() function from R’s base graphics.

For this example, we’ll use a subset of the countries data set. We’ll pull out the data for the year 2009, and keep only the columns that are relevant:

library(gcookbook) # For the data set
c2009 <- subset(countries, Year==2009,
                select=c(Name, GDP, laborrate, healthexp, infmortality))

c2009

        Name        GDP laborrate  healthexp infmortality
Afghanistan          NA      59.8   50.88597        103.2
    Albania   3772.6047      59.5  264.60406         17.2
    Algeria   4022.1989      58.5  267.94653         32.0
...
     Zambia   1006.3882      69.2   47.05637         71.5
   Zimbabwe    467.8534      66.8         NA         52.2

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint