開始使用免費開始

有序點圖

先來改進一下投影片中的點圖。

首先,把資料處理流程改成只篩選年份 19922002,而不是預設的 2006-2016。注意,陣列 interestingCountries 已經載入,內容與投影片相同。

接著修改繪圖程式碼以繪製新的資料;但這次請把 y 軸依 1992 年的病例數以遞減順序重新排序。

本練習屬於課程

R 視覺化最佳實務

檢視課程

練習說明

  • 修改 filter(),只取年份 19922002

  • 調整 Aesthetics:

    • 以國家為單位繪製 1992 年的病例數。
    • 使用 reorder() 依病例數重新排序 y 軸。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

who_subset <- who_disease %>% 
	filter(
		countryCode %in% interestingCountries,
		disease == 'measles',
		year %in% c(2006, 2016) # Modify years to 1992 and 2002
	) %>% 
	mutate(year = paste0('cases_', year)) %>%
	arrange(year, region) %>%
	pivot_wider(names_from = year, values_from = cases)
 
# Reorder y axis and change the cases year to 1992
ggplot(who_subset, aes(x = log10(cases_2006), y = country)) +
	geom_point()
編輯並執行程式碼