如何为离散值生成有意义的制图员/相关图 [英] How to produce a meaningful draftsman/correlation plot for discrete values

查看:115
本文介绍了如何为离散值生成有意义的制图员/相关图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最喜欢的探索性分析工具之一是pairs(),但是在离散值数量有限的情况下,由于点都完全对齐,它会变得平坦.请考虑以下内容:

One of my favorite tools for exploratory analysis is pairs(), however in the case of a limited number of discrete values, it falls flat as the dots all align perfectly. Consider the following:

y <- t(rmultinom(n=1000,size=4,prob=rep(.25,4)))
pairs(y)

它并没有真正带来良好的关联感.有替代的情节样式吗?

It doesn't really give a good sense of correlation. Is there an alternative plot style that would?

推荐答案

如果将y更改为data.frame,则可以添加一些抖动",并使用col选项可以设置透明度(rgb中的第4个数字) ):

If you change y to a data.frame you can add some 'jitter' and with the col option you can set the transparency level (the 4th number in rgb):

y <- data.frame(y)
pairs(sapply(y,jitter), col = rgb(0,0,0,.2))

或者您可以使用ggplot2的plotmatrix:

Or you could use ggplot2's plotmatrix:

library(ggplot2)
plotmatrix(y) + geom_jitter(alpha = .2)

由于ggplot2中的plotmatrix已被弃用,请使用ggpairs(上面@hadley的注释中提到的GGally包)

Since plotmatrix in ggplot2 is deprecated use ggpairs (GGally package mentioned in @hadley's comment above)

library(GGally)
ggpairs(y, lower = list(params = c(alpha = .2, position = "jitter")))

这篇关于如何为离散值生成有意义的制图员/相关图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆