scatterplot martix for two dataframes

Hello everyone!

I am new to R and I wonder if there is a, possibly easy, way to show a matrix of correlation scatterplots for variables from two data frames (one has 14 and the other 26 variables).

I have found options for correlating one set of variables with itself and nice visualisations - like ggpairs provides (e.g. here http://www.sthda.com/english/wiki/ggally-r-package-extension-to-ggplot2-for-correlation-matrix-and-survival-plots-r-software-and-data-visualization). However, cannot find solution for scatterplotting variables of 2 different dataframes..

Can anyone point me in the right direction how to do this?
OR simply make a series of such plots (does not have to be a matrix after all)?

Thank you and have a good day.

Hello leoncio,

In general ggplot2 expects your data as one single data frame and it's way easier to handle in most cases. What's wrong with combining the two into one?

Not sure if this is exactly what you are looking for but the {ggally} package provides several approaches to plot many variables at once, for example a ggscatman() function.

Hello,
thanks for replying Z3tt. The reason I split my dataframe with 40 variables into two with 14 and 26 variables is the fact that I had tried to use GGally on the whole set, and the plot matrix became illegible with 40 rows and 40 columns.
I usually need to correlate different sets of variables and have no need to correlate/scatterplot either set with itself.

That makes sense. So what ultimate aim? I cannot think of anything else than a correlation plot or a similiar heatmap.

Maybe that can be handled by ggduo

library(tidyverse)
library(GGally)
mycars <- select_if(mtcars, is.numeric)


ggduo(data=mycars,
      columnsX = names(mycars)[1:6],
      columnsY = names(mycars)[7:11])

The aim is to inspect the plots visually for outliers, non-linear relationships etc.
Of course it would be great if I could create such martices for distributions/histograms too.
(However they would have to be created separately, as opposed to nice GGally visualizations, as the rows would have different variables from the columns).

UPDATE.

I have not found a way to make scatterplot matrix.
However, I found a potential solution of making a series of plots which I will try to use with my data.
The instructions are by Ariel Muldoon under this http

1 Like

Great! Thank you very much!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.