始める無料で始める

順序付きポイントチャート

まずはスライドで見たポイントプロットを改良していきます。

はじめに、データ加工のパイプラインを変更して、デフォルトの 2006-2016 ではなく 19922002 の年に絞り込みます。配列 interestingCountries は読み込まれており、スライドと同じ内容です。

次に、プロット用のコードを新しいデータに合わせて修正します。今回は、1992 年の症例数に基づいて y 軸を降順に並べ替えて表示しましょう。

この演習はコースの一部です

R による可視化ベストプラクティス

コースを見る

演習の手順

  • filter() を修正して、年 19922002 を抽出します。

  • 美的属性(Aesthetics)を次のように変更します:

    • 国別に 1992 年の症例数をプロットする。
    • 症例数で y 軸を reorder() する。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

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()
コードを編集して実行