O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Multivariate plots with the GGally package

With the GGally package, we can create a multivariate plot of an entire data frame. It's pretty useful to have the big picture of a dataset. Ggpairs integrates with the other ggplot functions and automatically selects a visualization for each segment of the grid. We will create one with the previously viewed auto dataset. If you have not imported it, perform the following commands:

> auto <- read.csv("auto-mpg.csv", stringsAsFactors=FALSE) > auto$cylinders <- factor(auto$cylinders,labels=c("3cyl","4cyl", "5cyl","6cyl","8cyl"))

Now use the ggpairs() function to create the plot; we will only select mpg, cylinders, displacement, and horsepower:

> ggpairs(auto[,2:5])

Look at the results in the following ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required