ggplot2 plotmatrix有自由尺度

时间:2012-10-26 19:00:59

标签: r statistics ggplot2

我使用plotmatrix来查找数据框中的相关性:

# Reduce dataset to 1000 to make things run faster
d <- diamonds[sample(nrow(diamonds), 1000),]
plotmatrix(d[,-c(2:4)]) + geom_smooth(color="steelblue", method="lm")

只要不同的列具有相同的比例,这样就可以正常工作。如果不是,那么小规模的列就变得无用了。正如您所看到的,如果您运行上面的示例,价格是最大的,因此它会杀死所有其他列。

要在网格中解决这个问题,我通常会要求ggplot使用以下方法独立绘制每个比例:

scales="free_x"

但是,我怎样才能将其传递给plotmatrix,或者以某种方式独立制作plotmatrix scale?

enter image description here

1 个答案:

答案 0 :(得分:0)

基于上面的joran的评论,使用GGally包中的ggpairs:

# Reduce dataset to 1000 to make things run faster
d <- diamonds[sample(nrow(diamonds), 1000),]
ggpairs(d[,-c(2:4)], lower=list(continuous = "smooth"))