2012-06-27 12 views
15

Rを使って非常に基本的な世界地図を作成し、マラリア固有の国であることを示す赤い色で塗りつぶした特定の国を設定したいと思います。Rで世界地図を作成するにはどうすればいいですか?

私はデータフレームにこれらの国のリストを持っていますが、それらを世界地図に重ねるのに苦労しています。

私はwrld_simplオブジェクトとパッケージのjoinCountryData2Mapメソッドを使用しようとしました。

おそらく冗長な質問の追加を防ぐためにこの回答にコメントしたいと思いますが、私は現時点で十分な評判を得ていません。申し訳ありません。

https://stackoverflow.com/a/9102797/1470099

私は困難plot()コマンドに与えられた引数を理解することを持っています - wrld_simpl地図上の私のリストに国名のすべてをプロットするためにRを伝える代わりにするだけの簡単な方法があった場合、私は疑問に思いましたなどなど

plot(wrld_simpl, 
    col = c(gray(.80), "red")[grepl("^U", [email protected]$NAME) + 1]) 
+0

@ttmaccerを、なぜ答えとしてそれを追加しますか? – A5C1D2H2I1M1N2O1R2T1

答えて

17

rworldmapパッケージを使用して、あなたは次のように使用できます。

library(rworldmap) 

theCountries <- c("DEU", "COD", "BFA") 
# These are the ISO3 names of the countries you'd like to plot in red 

malDF <- data.frame(country = c("DEU", "COD", "BFA"), 
    malaria = c(1, 1, 1)) 
# malDF is a data.frame with the ISO3 country names plus a variable to 
# merge to the map data 

malMap <- joinCountryData2Map(malDF, joinCode = "ISO3", 
    nameJoinColumn = "country") 
# This will join your malDF data.frame to the country map data 

mapCountryData(malMap, nameColumnToPlot="malaria", catMethod = "categorical", 
    missingCountryCol = gray(.8)) 
# And this will plot it, with the trick that the color palette's first 
# color is red 
+0

本当にありがとう、これは本当に私を助けました...まだ地図に表示されない小さなアフリカ諸国のいくつかを持っていますが、それは別の日の仕事になります! – phlancelot

12

googleVisパッケージを使用して試してみて、使用gvisGeoMap機能

などをgrepl()を使用して

G1 <- gvisGeoMap(Exports,locationvar='Country',numvar='Profit',options=list(dataMode='regions')) 

plot(G1) 
+1

うわー、私はどのように強力なgoogleVisがあるか分からなかった!非常に単純な構文で、spatialPointsDataFrameを心配する必要はなく、出力は美しいです! –

3
library(maptools) 
    data(wrld_simpl) 
    myCountries = [email protected]$NAME %in% c("Australia", "United Kingdom", "Germany", "United States", "Sweden", "Netherlands", "New Zealand") 
    plot(wrld_simpl, col = c(gray(.80), "red")[myCountries+1]) 

enter image description here

関連する問題