gpt4 book ai didi

r - ggplot2 意外的 vapply 错误

转载 作者:行者123 更新时间:2023-12-04 10:08:19 24 4
gpt4 key购买 nike

让我们考虑以下示例:

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) 我删除了 data.frame 中的一行,或者如果我再添加 2 行,每个行都有一个新组,或者

b) 我删除 strip.placement = "outside"strip.position = "bottom"
这是一个错误吗?我错过了什么?为了美观,我想保留 strip 设置...

最佳答案

我不知道你的代码有什么问题,它在 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")

输出是这样的...希望这会有所帮助 Output Plot

关于r - ggplot2 意外的 vapply 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50385053/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com