ggplot2出现意外的vapply错误

7

让我们考虑以下示例:

library(ggplot2)

zzz <- data.frame(gp = c("a","b","c","d","e","f","g","h","i","j","k","l","m"), 
              c1 = c(1,1,1,1,1,1,1,1,1,1,1,1,1), 
              c2 = c(1,1,1,1,1,1,1,1,1,1,1,1,1))

ggplot(zzz, aes(x = c1, y = c2)) +
  facet_wrap(~ gp, scales = "free", strip.position = "bottom") +
  geom_point() +
  theme(
    aspect.ratio = 1,
    strip.background = element_blank(),
    strip.placement = "outside"
  )

为什么我会出现以下错误?我该如何克服它?
Error in vapply(row_axes, is.zero, logical(length(row_axes))) : 
values must be length 3,
but FUN(X[[1]]) result is length 1

我测试过一些调整,发现如果:

a)我从数据框中删除一行,或者添加2行,并为每个新组添加一个组名,则没有问题,或者

b)我删除strip.placement =“outside”strip.position =“bottom”

那是一个bug吗? 我错过了什么吗? 我想保留美学的条纹设置...


3
确实。如果一行中有空槽并且同时使用了“bottom”参数,似乎存在一个错误。使用“left”参数是有效的。 - Roman
1
是的,对我来说似乎是个错误。你可以在这里报告它。 - Axeman
2
报告位于 https://github.com/tidyverse/ggplot2/issues/2622 - user2165907
2
问题已在上面的 GH 线程中得到解决。当前版本的 ggplot2(3.1.0)不再返回此错误。投票关闭,因为该问题已无法再现。 - Z.Lin
1个回答

0

我不知道你的代码有什么问题,在 scales/strip.plavcement 中。

这段代码对我起作用:

library(ggplot2)

zzz <- data.frame(gp = c("a","b","c","d","e","f","g","h","i","j","k","l","m"), 
                  c1 = c(1,1,1,1,1,1,1,1,1,1,1,1,1), 
                  c2 = c(1,1,1,1,1,1,1,1,1,1,1,1,1))
str(zzz)
zzz$c1=as.character(zzz$c1)
zzz$c2=as.character(zzz$c2)
ggplot(zzz, aes(x = c1, y = c2)) +geom_point() +
  # facet_wrap(~ gp, scales = "free", strip.position = "bottom") 
  facet_wrap(~gp,nrow=1,strip.position = "bottom")+
  theme(panel.background = element_blank(),
        strip.background = element_blank(),axis.text.x=element_blank())
  # theme(
  #   aspect.ratio = 1,
  #   strip.background = element_blank(),
  #   strip.placement = "outside")

输出结果如下...希望这可以帮到你 输出图


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接