【发布时间】:2015-11-10 14:50:57
【问题描述】:
我正在尝试使用 dplyr 包中的 filter 命令过滤掉一堆数据。一切似乎都如我所愿,但是当我尝试从新过滤的数据中绘制一些图表时,我过滤掉的所有级别都显示出来了(尽管没有值)。但是他们在那里的事实仍然使我的水平轴偏离了。
那么两个问题:
1) 为什么这些过滤后的级别仍在数据中?
2) 我如何过滤以使这些不再存在?
这是一个小例子,你可以运行看看我在说什么:
library(dplyr)
library(ggvis)
# small example frame
data <- data.frame(
x = c(1:10),
y = rep(c("yes", "no"), 5)
)
# filtering to only include data with "yes" in y variable
new_data <- data %>%
filter(y == "yes")
levels(new_data) ## Why is "no" showing up as a level for this if I've filtered that out?
# Illustration of the filtered values still showing up on axis
new_data %>%
ggvis(~y, ~x) %>%
layer_bars()
感谢您的帮助。
【问题讨论】: