点太多的散点图 [英] Scatterplot with too many points

查看:39
本文介绍了点太多的散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图绘制两个变量,其中 N=700K.问题是重叠太多,以至于情节大部分变成了实心的黑色块.有没有办法让一个灰度云",其中绘图的暗度是一个区域中点数的函数?换句话说,我不希望显示单个点,而是希望绘图是一个云",一个区域中的点数越多,该区域越暗.

I am trying to plot two variables where N=700K. The problem is that there is too much overlap, so that the plot becomes mostly a solid block of black. Is there any way of having a grayscale "cloud" where the darkness of the plot is a function of the number of points in an region? In other words, instead of showing individual points, I want the plot to be a "cloud", with the more the number of points in a region, the darker that region.

推荐答案

处理这个问题的一种方法是使用 alpha 混合,它使每个点都略微透明.因此,在其上绘制了更多点的区域显得更暗.

One way to deal with this is with alpha blending, which makes each point slightly transparent. So regions appear darker that have more point plotted on them.

这在 ggplot2 中很容易做到:

This is easy to do in ggplot2:

df <- data.frame(x = rnorm(5000),y=rnorm(5000))
ggplot(df,aes(x=x,y=y)) + geom_point(alpha = 0.3)

另一种方便的处理方法是(可能更适合您拥有的点数)是六边形分箱:

Another convenient way to deal with this is (and probably more appropriate for the number of points you have) is hexagonal binning:

ggplot(df,aes(x=x,y=y)) + stat_binhex()

并且还有常规的旧矩形分箱(图像省略),这更像您的传统热图:

And there is also regular old rectangular binning (image omitted), which is more like your traditional heatmap:

ggplot(df,aes(x=x,y=y)) + geom_bin2d()

这篇关于点太多的散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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