Extract the last row of a pairs plot in R

318 views Asked by At

I have created this pairs plot of a 10X10 data frame. I am interested in extracting only the last row, as it shows the covariates (on x axis) against the response parameter of interest (on y axis) for each covariate. I have used basic R pairs plot, but if a solution exist for ggpairs I can easily modify the code below.

pairs.panels(data, smooth = TRUE, scale = FALSE, density = TRUE, ellipses = FALSE)

The pairs plot looks like this: enter image description here

2

There are 2 answers

0
DaveArmstrong On

I wrote a package called psre (you can install it from CRAN) and it has a function called lsa() (which stands for Linear Scatterplot Array). The function does what you want. Here's how it works:

library(psre)
data(wvs)
lsa(sacsecval ~ resemaval + moral + 
                pct_univ_degree + pct_female + 
                pct_low_income, 
    xlabels = c("Emancipative Vals", "Moral Perm", 
                "% Univ Degree", "% Female", "% Low Income"), 
    ylab = "Secular Values", 
    data=wvs)

enter image description here

0
Darren Tsai On

Use the arg horInd, which is documented in ?graphics::pairs.

library(psych)

pairs.panels(attitude, horInd = 7)

enter image description here

The original output:

pairs.panels(attitude)

enter image description here