简体   繁体   中英

ggplot2 unexpected vapply error

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...

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 输出图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM