开始使用免费开始使用

比较 2007 年各大洲的中位预期寿命与中位 GDP

在前面的练习中,您通常绘制的是随时间变化的图表。作为另一种可视化探索数据的方式,您也可以使用 ggplot2 绘制汇总后的数据,在同一年内比较各大洲。

本练习是课程的一部分

Tidyverse 入门

查看课程

练习说明

  • 先对 gapminder 数据集筛选年份为 2007,然后在「每个大洲内」汇总人均 GDP 的中位数和预期寿命的中位数,列名分别为 medianLifeExpmedianGdpPercap。将结果保存为 by_continent_2007
  • 使用 by_continent_2007 数据创建散点图,比较 2007 年各大洲的这些汇总统计量,将人均 GDP 的中位数放在 x 轴,预期寿命的中位数放在 y 轴。用 continent 为散点着色。此图不需要添加 expand_limits(y = 0)

交互式实操练习

通过完成这段示例代码来试试这个练习。

library(gapminder)
library(dplyr)
library(ggplot2)

# Summarize the median GDP and median life expectancy per continent in 2007


# Use a scatter plot to compare the median GDP and median life expectancy
编辑并运行代码