2012-06-27 4 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

관련 문제