r语言 - ggplot2 vs cowplot, 错误在 FUN( "text" [[1L]], ...) :



我试图使用cowplot来组合一些ggplot2情节。它应该是直接的,但是我的R或Rstudio中的某些东西坏了。我不知道的。我可以让它和网格一起工作。整理,但是我的markdown文件中的输出不那么好。我将我的代码分解到最小数量,以重新创建错误,并退出markdown

library(ggplot2)
library(Hmisc)
library(cowplot)

x <- c(1, 8, 9)
y <- c(1, 5, 9)
supply1 <- data.frame(bezier(x, y, evaluation = 500))
g1 <- ggplot(x = 0:10, y = 0:10, geom = "blank") +
  geom_path(data = supply1, aes(x = x, y = y), size = 1, colour = "BLUE")
g2 <- ggplot(x = 0:10, y = 0:10, geom = "blank") +
  geom_path(data = supply1, aes(x = x+1.5, y = y+1.5), size = 1, colour = "RED")

plot_grid(g1, g2,
          ncol = 2, 
          nrow = 1)

我得到这个错误:

错误有趣("text"[[1 l ]], ...) :

主题元素'text'有NULL属性:margin, debug

我必须分离cowplot,但可以使用以下代码与gridExtra接近:

library(ggplot2)
library(Hmisc)
library(gridExtra)

x <- c(1, 8, 9)
y <- c(1, 5, 9)
supply1 <- data.frame(bezier(x, y, evaluation = 500))
g1 <- ggplot(x = 0:10, y = 0:10, geom = "blank") +
  geom_path(data = supply1, aes(x = x, y = y), size = 1, colour = "BLUE")
g2 <- ggplot(x = 0:10, y = 0:10, geom = "blank") +
  geom_path(data = supply1, aes(x = x+1.5, y = y+1.5), size = 1, colour = "RED")
grid.arrange(g1,g2,
             ncol = 2,
             nrow = 1)

这段代码输出:网格。安排情节

原来我得到了" FUN消息"错误;如果我尝试在加载了ggplot2和cowplot库的情况下制作任何ggplot。R 3.1.3, RStudio 0.99.903, cowplot 0.4.0, ggplot2 2.1.0

我已经重新安装了至少两次,并在不同的计算机上得到相同的错误情况。我可以让它以有限的方式工作。如果我在运行了除plot_grid()块之外的所有其他代码之后再调用cowplot库,那么它将编织并为我提供cowplot输出。我不能在R脚本中重新创建这只在Rmarkdown,但然后我必须让它成为markdown的最后一块,任何ggplot尝试之后,它将导致编织失败。

短期我使用grid.arrange(),只是生活的结果,长期我想有cowplot作为一个选项。

有什么想法或建议吗?

显然这是一个自R 3.3.1以来已经修复的错误,因此升级到这个版本或更新版本应该会消失。

最新更新