ggplot2 unexpected vapply error

限于喜欢 提交于 2019-12-08 20:02:05

问题


Let's consider the following example:

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"
  )

Why do I get the following error? And how could I overcome it?

Error in vapply(row_axes, is.zero, logical(length(row_axes))) : 
values must be length 3,
but FUN(X[[1]]) result is length 1

Some tweaks I tested revealed that there is no issue if:

a) I remove one line in the data.frame or if I add 2 more lines with a new group for each, or

b) I remove strip.placement = "outside" or strip.position = "bottom"

Is that a bug? Did I miss something? I would like to keep the strip settings for aesthetics...


回答1:


I don't know what the problem was in your code, it's in scales/strip.plavcement.

This code worked for me:

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")

The output is this...hope this helps



来源:https://stackoverflow.com/questions/50385053/ggplot2-unexpected-vapply-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!