GGally - unexpected behavior with ggpairs(…, diag = list( continuous = 'density'))

非 Y 不嫁゛ 提交于 2019-12-20 12:32:21

问题


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.


回答1:


So I finally figured this out, by studying a different question here. It turns out that unless axisLabels is set to "show", density plots on the diagonal are suppressed, without warning.

xx <- mtcars[,c(1,3,4,6)]   ## extract mpg, disp, hp, and wt from mtcars
library(GGally)
ggpairs(xx, diag=list(continuous="density"), axisLabels='show')

Produces this, as expected:



来源:https://stackoverflow.com/questions/20079977/ggally-unexpected-behavior-with-ggpairs-diag-list-continuous-densit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!