各国の色がデータ フレームに格納されている特定の値に対応する世界地図のプロットを生成しようとしています。
> aggregated_country_data
country num_responses region
1 AL 1 Albania
2 AM 1 Armenia
3 AR 32 Argentina
...
75 ZW 3 Zimbabwe
これは私が試したものです
library(rworldmap)
library(ggplot2)
map.world <- map_data(map="world")
gg <- ggplot()
gg <- gg + theme(legend.position="none")
gg <- gg + geom_map(data=map.world, map=map.world, aes(map_id=region, x=long, y=lat), fill="white", colour="black", size=0.25)
gg
これで世界地図がうまくプロットされたので、次に、aggregated_country_data の値「num_responses」に比例して各国に色を追加します。
gg <- gg + geom_map(data=aggregated_country_data, map=map.world, aes(map_id=region, fill=num_responses), color="white", size=0.25)
gg
ただし、aggregated_country_data の列 num_responses にある値ではなく、国コードに対応するため、各色が色分けされています。
私が得ていないggplot2について何かがあることは明らかですが、それが何であるかはわかりません。
ご意見をいただければ幸いです、ブラッド
私は問題が何であるかを理解しました.ggplot2や私がしていたこととは何の関係もありません. aggregated_country_data データ フレームの「地域」の名前は、map.world とは異なります。私の入力データ (aggregated_country_data) は、countrycode R パッケージを使用して国名 (データ フレームでは「地域」と呼ばれます) に変換した 2 文字の国コードをデフォルトで使用しますが、名前に存在するものとは異なる命名規則を使用していますマップ.ワールド。ですから、それはまったく別の問題です。