Year <- c(rep(c("2006-07", "2007-08", "2008-09", "2009-10"), each = 4))
Category <- c(rep(c("A", "B", "C", "D"), times = 4))
Frequency <- c(168, 259, 226, 340, 216, 431, 319, 368, 423, 645, 234, 685, 166, 467, 274, 251)
Data <- data.frame(Year, Category, Frequency)
library(ggplot2)
p <- qplot(Year, Frequency, data = Data, geom = "bar", fill = Category, theme_set(theme_bw()))
假设我有上面的代码/数据。我只对绘制值(如果它们总计(堆栈)到1000以上)感兴趣。这是否可以在ggplot代码中使用简单的子集命令?
答案 0 :(得分:1)
我认为ggplot
本身并不可能,但使用dplyr
相对简单,然后您可以传入您想要绘制的数据。 E.g:
Data %>%
group_by(Year) %>%
mutate(Total = sum(Frequency)) %>%
filter(Total > 1000)