我真的很喜欢 ggplot 中的 hexbin 密度图的想法,并且我尽可能地尝试使用它(而不是由 stat_bin2d 生成的方形 bin)。然而,六边形的边界有时是明显的。例如,
d <- ggplot(钻石,aes(克拉,价格))
d + stat_binhex()
在这张图片中,六边形的边界显示为小白线,这有时会干扰我想象图片中真实“密度”变化的尝试。
如果我使用 stat_bin2d,则根本不显示边界线:
d <- ggplot(钻石,aes(克拉,价格))
d + stat_bin2d()
所以我的问题是:
非常感谢!
旁白:我更喜欢在 ggplot 中做六边形密度图而不是使用其他一些包,主要是因为我喜欢稍后添加其他层的灵活性。
最佳答案
使用指向 ggplot2 multiple stat_binhex() plots with different color gradients in one image 的链接作为引用,我能够使用以下代码完成您的要求:
d <- ggplot(diamonds, aes(carat, price))
d + stat_binhex(aes(colour = ..count..))
或者
d <- ggplot(diamonds, aes(carat, price, colour = ..count..))
d + stat_binhex()
关于r - 如何摆脱ggplot geom_hex中的边界线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34700648/