R geom_tile 宽度和高度在 ggplotly 中被忽略

发布于 2025-01-18 16:21:02 字数 568 浏览 2 评论 0原文

高度width geom_tile的参数在转换为ggplotly时,不会考虑考虑下面的示例。有工作吗?请注意,我的数据集实际上很大(+80k数据点),因此,如果有一个,我会赞成有效的解决方案。

library(plotly)

X <- data.frame(x = c(1, 2, 1, 2), y = c(1, 1, 2, 2), z = 1:4)
gg <- ggplot(X, aes(x, y)) + geom_tile(aes(fill = z), width = .5, height = .5)

gg
ggplotly(gg)

The height and width parameters of geom_tile are not being taken into account when converted to ggplotly, as shown in the example below. Is there a work around? Please note that my dataset is in fact very large (+80k data points), so I would favor an efficient solution, if there is one.

library(plotly)

X <- data.frame(x = c(1, 2, 1, 2), y = c(1, 1, 2, 2), z = 1:4)
gg <- ggplot(X, aes(x, y)) + geom_tile(aes(fill = z), width = .5, height = .5)

gg
ggplotly(gg)

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜访吸血鬼 2025-01-25 16:21:02

这似乎是 ggplotly 中的一个错误。最简单的方法是将 geom_tile 转换为 geom_rect。我认为这不会比 geom_tile 效率低,因为您只是复制 geom_tile 内部所做的事情。

library(plotly)

X <- data.frame(x = c(1, 2, 1, 2), y = c(1, 1, 2, 2), z = 1:4)

width <- .5
height <- .5

gg <- ggplot(X, aes(x, y)) + 
  geom_rect(aes(xmin = x - width/2, xmax = x + width/2, 
                ymin = y - height/2, ymax = y + height/2, fill = z))

ggplotly(gg)

输入图片此处描述

This seems to be a bug in ggplotly. The easiest thing would be to convert your geom_tile to geom_rect. I don't think this will be any less efficient than geom_tile, since you are just replicating what geom_tile does internally.

library(plotly)

X <- data.frame(x = c(1, 2, 1, 2), y = c(1, 1, 2, 2), z = 1:4)

width <- .5
height <- .5

gg <- ggplot(X, aes(x, y)) + 
  geom_rect(aes(xmin = x - width/2, xmax = x + width/2, 
                ymin = y - height/2, ymax = y + height/2, fill = z))

ggplotly(gg)

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文