【发布时间】:2019-10-13 04:15:15
【问题描述】:
我正在尝试为每年最常使用的单词绘制条形图,但 ggplot 仅绘制一个图表
word frequency Year
easy use easy use 9 2019
value money value money 8 2019
project management project management 4 2019
business management business management 3 2019
customer serviceâ€\u009d customer serviceâ€\u009d 3 2019
everything need everything need 3 2019
tail(unified)
word frequency Year
workflows support workflows support 1 2014
working people working people 1 2014
works helpful works helpful 1 2014
worth try1 worth try 1 2014
write invoices write invoices 1 2014
years research years research 1 2014
ggplot(head(unified,25), aes(reorder(word,-frequency), frequency)) +
geom_bar(stat = "identity") + facet_wrap(~Year) + theme(axis.text.x = element_text(angle=90, hjust=1)) + xlab("Bigrams") + ylab("Frequency") +
ggtitle("Most frequent bigrams for all years")
我的 ggplot 只生成 2019 年的条形图。请帮助
【问题讨论】:
-
您的意思是将
head(unified,25)放入ggplot中吗?ggplot可能只读取前 25 行。 -
是的,我只需要前 25 个条目
-
我想你想要像
library(dplyr); dplyr::group_by(unified, Year) %>% dplyr::top_n(25, frequency)这样的东西作为ggplot的data参数的输入 -
我想为前 25 个单词在所有年份中对应的频率绘制一个条形图
标签: r ggplot2 bar-chart facet-wrap