gpt4 book ai didi

r - ggplotGrob 对象上的 cbind 失败,错误为 "Error in mmm < each : comparison of these types is not implemented"

转载 作者:行者123 更新时间:2023-12-04 10:46:59 24 4
gpt4 key购买 nike

这似乎与@baptiste 在 2014 年试图解决的问题类似。我正在重新审视我在 6 月份编写的代码,其中涉及创建三个 ggplotGrob 并将它们与对 cbind 的调用结合起来。现在,此代码失败并显示消息:“mmm < each 中的错误:未实现这些类型的比较。”

我认为这将特定于我的特定应用程序,但我能够制作一个非常简单、可重现的示例。即使在两个相同的 ggplotGrobs 上执行 cbind,此代码仍然失败。

library(ggplot2)
library(gtable)

# Make some plots
pl1 <- ggplot(mtcars, aes(x = disp, y = mpg)) +
geom_point()
pl2 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) +
geom_point()

# Convert to grobs
pl1_grob <- ggplotGrob(pl1)
pl2_grob <- ggplotGrob(pl2)

# Bind them together -- Error!
combined_grob <- cbind(pl1_grob, pl2_grob)

错误和相关回溯在这里:
> combined_grob <- cbind(pl1_grob, pl2_grob)
Error in mmm < each : comparison of these types is not implemented
> traceback()
8: comp(x_val, y_val)
7: unit(comp(x_val, y_val), x_unit)
6: compare_unit(x$heights, y$heights, pmax)
5: cbind_gtable(x, y, size = size)
4: f(init, x[[i]])
3: Reduce(function(x, y) cbind_gtable(x, y, size = size), gtables)
2: cbind(deparse.level, ...)
1: cbind(pl1_grob, pl2_grob)

此代码在 OS X 10.11.6 上使用 grid_3.4.2、gtable_0.2.0 和 ggplot2_2.2.1 使用 R-3.4.2 失败,在 Linux 上使用 R-3.3.2(从 Ubuntu 16.04 上的源代码编译)使用 grid_3.3.2 失败、gtable_0.2.0 和 ggplot2_2.2.1。

在制作上面的示例之前,我注意到“lemon”包(“gtable_show_lemonade”)中的一个小插曲在接近最后阶段失败,并在两个 gtables 的 cbind 上出现相同的错误。我通过从源代码运行此小插图的代码来确认此错误,如下所示:
library(lemon)
edit(vignette('gtable_show_lemonade', package = 'lemon'))
# Then use whichever editor you opened to copy the temporary filename
# of the vignette source, and run this with source()

编译的小插图(cbind 失败)在这里: https://cran.r-project.org/web/packages/lemon/vignettes/gtable_show_lemonade.html

小插图编译期间的失败是使用在 OS X 10.11 (El Capitan) 上运行的上述 R-3.4.2 实例获得的。

我将不胜感激任何有关解决此问题的帮助!由于我想使用我的 Mac 来生成数字(更好的字体情况),我希望有一种方法可以重载一个函数来解决这个问题。

更新:

如果 size = 'max',这“仅”是一个问题指定了默认值(或 size = 'min')。我认为我可以使用 size = 'first' 解决它或 size = 'last' ,它不执行有问题的高度比较,但默认行为不起作用肯定不方便(在某些情况下 size = 'max' 很有用)。

最佳答案

我从来没有设法在 gtable 中解决这个问题,所以 gridExtra 有一个名为 gtable_cbind 的修改版本.

关于r - ggplotGrob 对象上的 cbind 失败,错误为 "Error in mmm < each : comparison of these types is not implemented",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47278868/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com