我试图在对角线中生成一个带有密度图的散点图矩阵(最好使用ggplot).ggpairs
GGally包中的文档说明:
diag是一个列表,可能只包含变量'continuous'和'discrete'.diag列表的每个元素都是一个实现以下选项的字符串:continuous =恰好其中一个('density','bar','blank'); discrete =恰好其中一个('bar','blank').
这表明(??)这应该可以使用diag=list(continuous="density")
.
但是以下代码:
xx <- mtcars[,c(1,3,4,6)] ## extract mpg, disp, hp, and wt from mtcars
library(GGally)
ggpairs(xx,diag=list(continuous="density"))
Run Code Online (Sandbox Code Playgroud)
给出这个:
我究竟做错了什么?
注意:尝试做同样的事情plotmatrix(xx)
给出了这个:
这是因为密度图显然是使用基于完整数据集(xx
)的范围在每个对角线面上缩放,而不是基于xx
适当面的子集的范围.结果,第二行(disp)看起来很好,因为disp具有最大范围,但是第1行和第4行是嘎吱嘎吱的.
jlh*_*ard 11
所以我最终通过研究一个不同的问题来解决这个问题.事实证明,除非axisLabels
设置为"show"
,否则对角线上的密度图被抑制,没有警告.
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')
Run Code Online (Sandbox Code Playgroud)
正如预期的那样产生这个: