按标签可视化问题与回答
在上一个练习中,您修改了 posts_with_tags 表,新增了 year 列,并按 type、year 和 tag_name 做了聚合。修改后的表已为您预加载为 by_type_year_tag,其中每条观测对应一个类型(问题/回答)、年份和标签。现在请创建一幅图,查看该表中关于 dplyr 和 ggplot2 标签的问题与回答信息。ggplot2 包已为您预加载。
by_type_year_tag <- posts_with_tags %>%
mutate(year = year(creation_date)) %>%
count(type, year, tag_name)
本练习是课程的一部分
使用 dplyr 进行数据表连接
练习说明
- 在
by_type_year_tag表中筛选出 dplyr 与 ggplot2 这两个标签。 - 使用筛选后的表创建折线图,绘制随时间变化的频数(
n),并按问题/回答着色、按标签分面展示。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Filter for the dplyr and ggplot2 tag names
by_type_year_tag_filtered <- by_type_year_tag %>%
filter(___)
# Create a line plot faceted by the tag name
ggplot(by_type_year_tag_filtered, aes(___, ___, color = ___)) +
geom_line() +
facet_wrap(~ tag_name)