【发布时间】:2017-08-25 11:35:34
【问题描述】:
我有一个通用的plot_data(data) 方法。有时传入的数据包含我用于 fill 的变量的所有 NA,这会导致错误
Error in seq.default(h[1], h[2], length.out = n) :
'to' must be a finite number
例如:
df <- data.frame(
x = c(1, 2, 3, 4),
y = c(10, 15, 20, 25),
foo = factor(c(NA, NA, NA, "yes"), levels=c("yes", "no"))
)
ggplot(df, aes(x=x, y=y, fill=foo))+geom_bar(stat = "identity") # works
ggplot(df[1:3, ], aes(x=x, y=y, fill=foo))+geom_bar(stat = "identity") # error
我不明白为什么情节不应该在案例 2 中呈现(只是所有灰色条)。有没有简单的方法可以解决这个问题?
【问题讨论】: