I am trying to generate a scatterplot matrix with density plots in the diagonals (using ggplot, preferably). The documentation for ggpairs
in the GGally package states:
diag is a list that may only contain the variables 'continuous' and 'discrete'. Each element of the diag list is a string implementing the following options: continuous = exactly one of ('density', 'bar', 'blank'); discrete = exactly one of ('bar', 'blank').
which suggests(??) that this should be possible using diag=list(continuous="density")
.
But the following code:
xx <- mtcars[,c(1,3,4,6)] ## extract mpg, disp, hp, and wt from mtcars
library(GGally)
ggpairs(xx,diag=list(continuous="density"))
gives this:
What am I doing wrong?
NB: Trying to do the same thing with plotmatrix(xx)
gives this:
which fails because the density plots are, evidently, scaled in each diagonal facet using the range based on the full dataset (xx
), rather than the range based on xx
subsetted for the appropriate facet. As a result, the second row (disp) looks good because disp has the greatest range, but rows 1 and 4 are crunched.