Can I use pairs() function in R and plot a subset of the default plots?

Viewed 846

I am trying to find the relationship between a selected target variable and the other variables in a data set. For example, if I consider the auto dataset I get the following plot. Assume my target variable is mpg

library("ISLR")
pairs(Auto)

Image of the plot

However, I would like to return only the first row of this plot since I'm only interested in plotting the relationship between the target variable and each of the other variables. I have seen this post which uses the tidyverse library and rearranges my dataframe.

I'm hoping there's a way to do it using just the pairs() function in R.

Edit: I'm looking for a way to keep the variable names in the final result.

1 Answers

Look for horInd and verInd in ?pairs.

For instance

pairs(mtcars, verInd = 1, horInd = 2:ncol(mtcars))
Related