ggplot2意外的vapply错误 [英] ggplot2 unexpected vapply error
本文介绍了ggplot2意外的vapply错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们考虑以下示例:
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)我删除了data.frame中的一行,或者如果我又添加了2行,每行又添加了一个新组,或者
a) I remove one line in the data.frame or if I add 2 more lines with a new group for each, or
b)我删除了strip.placement = "outside"
或strip.position = "bottom"
那是个错误吗?我错过了什么?我想保留带状设置的美感...
Is that a bug? Did I miss something? I would like to keep the strip settings for aesthetics...
推荐答案
我不知道您的代码中的问题是什么,它在scales/strip.plavcement
中.
I don't know what the problem was in your code, it's in 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")
输出为...希望此对
The output is this...hope this helps
这篇关于ggplot2意外的vapply错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文