当我运行简单代码时:
dataset1 = data.frame(xvar = 1:100, yvar=100:1)
dataset2 = data.frame(group_start = 1:5,
group_end = 2:6,
startval= c(4,9,15,36,50),
endval = c(9,15,36,50,100))
ggplot(dataset1, aes(x = xvar, y = yvar)) +
geom_point() +
geom_rect(data = dataset2,
mapping = aes(xmin = startval, xmax = endval,
ymin = group_start, ymax = group_end,
fill=t),
color="black",
alpha=0.5,
inherit.aes=FALSE)
我收到错误
Don't know how to automatically pick scale for object of type function.
Defaulting to continuous.
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
arguments imply differing number of rows: 5, 0
我想知道这意味着什么以及如何解决它。
鉴于消息的object of type function
部分,我检查了我的任何列名是否都是内置函数。答案是否定的。
我进一步检查了它是否与不同数据集中不同数据类型的不同列有关。当我将所有列更改为numeric
时,问题仍然存在。
答案 0 :(得分:1)
尝试将fill=t
更改为fill=as.factor(group_start)
或其他内容