按大洲随时间可视化人均 GDP 的中位数
在上一个练习中,您使用折线图可视化了人均 GDP 中位数随时间的增长。现在,您将查看各大洲内部的变化。
本练习是课程的一部分
Tidyverse 入门
练习说明
- 使用
group_by()和summarize()在"每个年份和大洲"内计算人均 GDP 的中位数,将输出列命名为medianGdpPercap。使用赋值运算符<-将结果保存为名为by_year_continent的数据集。 - 使用
by_year_continent数据集创建折线图,展示人均 GDP 中位数随时间的变化,并用颜色表示大洲。请务必使用expand_limits(y = 0),在 y 轴中包含 0。
交互式实操练习
通过完成这段示例代码来试试这个练习。
library(gapminder)
library(dplyr)
library(ggplot2)
# Summarize the median gdpPercap by year & continent, save as by_year_continent
# Create a line plot showing the change in medianGdpPercap by continent over time