使用ggplot2在R中不均匀的binning及其在R中的绘图
有没有办法在 geom_bin_2d 的 binwidth 内使用数字向量?我想创建一个具有不规则/不均匀分箱长度的分箱热图,但我不知道该怎么做。
一个可重现的例子
library(tidyverse)
data <- tibble(x = sample(100),
y = sample(100)) %>%
mutate(x = x * 1.2,
y = y * 0.8)
binX <- c(18, 39, 60, 81, 102, 120)
binY <- c(18, 30, 50, 62, 80)
data %>%
ggplot() +
geom_bin_2d(aes(x = x, y = y), binwidth = c(binX, binY))
Is there any way to use a vector of numbers within the binwidth for geom_bin_2d? I would like to create a binned heatmap with irregular/uneven bin lengths, but I am not sure how to do it.
A reproducible example
library(tidyverse)
data <- tibble(x = sample(100),
y = sample(100)) %>%
mutate(x = x * 1.2,
y = y * 0.8)
binX <- c(18, 39, 60, 81, 102, 120)
binY <- c(18, 30, 50, 62, 80)
data %>%
ggplot() +
geom_bin_2d(aes(x = x, y = y), binwidth = c(binX, binY))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将列表中的 x 和 y bin 传递给
breaks
参数:< img src="https://i.sstatic.net/WywhF.png" alt="在此处输入图像描述">
You can pass the x and y bins in a list to the
breaks
argument: