r - 如何在 ggplot2 中以对数刻度显示 stat_binhex

标签 r ggplot2 hexagonal-tiles

我有一个带有很多点的二维六边形密度图。我希望六边形内的计数以对数刻度显示,但我不知道如何通过 ggplot2 来做到这一点。

这是一个简单的例子:

x <- runif(1000, 50, 100) 
y <- rnorm(1000, mean = 10, sd = 8)

df <- as.data.frame(cbind(x, y))

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

最佳答案

有一个fill默认为 ..count.. 的美学当您未在 stat_binhex 中指定时.下面的代码生成与原始代码相同的图。

ggplot(df, aes(x, y)) + stat_binhex(aes(fill=..count..))

enter image description here

如果您想要计数的对数刻度,那么解决方案非常简单:
ggplot(df, aes(x, y)) + stat_binhex(aes(fill=log(..count..)))

enter image description here

关于r - 如何在 ggplot2 中以对数刻度显示 stat_binhex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26374083/

相关文章:

r - 指定 as.Date 格式在 R 中返回 NA

r - ggplot 和 plot 如何以不同方式处理 inf 值?

从ggplot2图中删除右边框

R 函数获取 rpart 应用的规则

重新调整一个因素

javascript - 六边形组周围的轮廓

以最小距离(3)为重复出现的颜色着色六边形瓦片 map 的算法

python - 将 matplotlib hexbin 放入 Aitoff 投影

r - 将类似 Excel 的功能添加到 R 图中的方法?

r - ggvis:将多个数据集合并在一个图中