開始使用免費開始

隨時間視覺化各洲的中位數人均 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
編輯並執行程式碼