開始使用免費開始

比較 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
編輯並執行程式碼