【发布时间】:2018-02-19 11:32:25
【问题描述】:
谁能告诉我如何将以下 dplyr 代码与 ggplot 条形图集成。我让它们都独立工作,但是每当我尝试将它们组合在一起时,就会出现问题。
这是生成汇总表的 dplyr 代码(插入到脚本下方):
pop.2.df %>%
gather(key = "trial", value = 'capture','sco.1','sco.2', 'sco.3') %>%
group_by(trial, capture) %>% summarise(n = n())
A tibble: 6 x 3
Groups: trial [?]
trial capture n
<chr> <chr> <int>
1 sco.1 n 28
2 sco.1 y 94
3 sco.2 n 38
4 sco.2 y 84
5 sco.3 n 45
6 sco.3 y 77
这是生成条形图的 ggplot 代码,但是如果我首先从上面的脚本中创建一个对象然后绘图,我只能让它工作。我希望使用管道运算符在一段代码中完成所有工作:
ggplot(data = pop.2.df.v2) + geom_bar(mapping = aes(x = trial, fill = capture), position = "dodge")
【问题讨论】:
-
代码中有数据有帮助,你可以随时使用 dput()
-
管道不适用于
your summarised data %>% ggplot() + etc? -
我确定它应该可以工作....但我无法获得正确的语法。