r - 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"
)
为什么我会收到以下错误?我怎么能克服它?
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"
那是一个错误吗?我错过了什么?我想保留条带设置以保持美观...
解决方案
我不知道你的代码有什么问题,它在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")
推荐阅读
- python - 数字的 Python 正则表达式问题
- c# - 如何从 .txt 文件创建的列表中删除一行?
- javascript - IOS设备不填充点击功能属性添加
- excel - 在excel中隔离行的第一个结果
- sql-server - SQL Server 2016 始终加密。我可以将始终加密用于数据仓库吗?如果没有,那么我有什么选择?
- excel - 电子表格公式导致工作簿变慢
- ruby - bash 中的正则表达式返回与 ruby 不同的结果
- javascript - xterm.js - 获取当前行文本
- php - 在 PHP 中使用 sqlsrv 防止 SQL 注入
- node.js - 如何将 fetch 转换为 axios