2012-02-16 8 views
31

최근 gorplot2를 사용하여 여러 choropleth를 만들었습니다. 이 (WorldMapper에서)이 비슷한지도를 만들 ggplot2를 사용하는 것이 가능했다 궁금 해서요 :카고로그 + choropleth지도 in R

enter image description here

그것은 Shape 파일의 다각형이 상대적으로 인구 수를 표현하기 위해 왜곡되어 choropleth입니다. 나는 이것이 cartogram이라고 믿는다. 그들은 다른 변수들로 이것을합니다. Choropleth R Challenge의 정신으로 누구나 R을 사용하여이를 수행하는 방법을 알고 있습니까?

+2

R 환경 외부의 cartograms [ScapeToad] (http://scapetoad.choros.ch/)를 시도해보십시오. – radek

+1

감사합니다. ScapeToad는 훌륭하게 작동하며 내 요구에 부응합니다. 그러나 R 내에서 해결책이있을 경우를 대비하여 질문을 떠날 것입니다. –

+4

d3-cartogram을 rCharts와 통합하기 시작했습니다. 데이터 구조는 무엇입니까? – timelyportfolio

답변

4

CRAN에서 사용할 수있는 cartogrampackage에는 원하는 고무 시트 왜곡 스타일 카토 그램이 있습니다.

1

작동 여부 :

FFTW를 사전 설치해야합니다. Rcartogram and getcartr you will need devtools.

ggplot2에서 수행하는 방법을 잘 모르겠지만 다른 옵션이 있습니다.

Thematic World Map에서 shapefile을 사용하고 있습니다. 다운로드하고 압축을 풀면 TM_WORLD_BORDERS-0.3 폴더가 생깁니다. choropleth/카르 토 그램의 경우

, 당신은 기능과 크기에 처음으로 재편하고, 그늘 것 :

enter image description here

:

library(rgdal)#needed for readOGR 
library(sp) #needed for spplot 
library(Rcartogram) 
library(getcartr) 
setwd("<your_directory_with_shapefile>") #to the file that has your shapefile and your information file (in this case, a csv named datR) 
#read shapefile 
#here i have a folder with a shapefile and a csv with columns as ISO (IS02 for convenience) country and value 
worldR <- readOGR(dsn = getwd(), layer= "TM_WORLD_BORDERS-0.3") # If reading a shapefile, the data source name (dsn= argument) is the folder (directory) where the shapefile is, and the layer is the name of the shapefile (without the .shp extension) 
#names(worldR) #note how here there are columns for ISO2 (which matches a column named 'iso' in datR and LAT\LON 
#[1] "FIPS"  "ISO2"  "ISO3"  "UN"  "NAME"  "AREA"  "POP2005" "REGION" "SUBREGION" "LON"  "LAT" 
proj4string(worldR) 
datR <- read.csv("datR.csv") #this is a file that has one column called 'score' and one column called size': 

    head(datR) 
    # iso size  score 
    #1 AE 323 0.9819077 
    #2 AR 262 0.9591067 
    #3 AT 7481 0.9987313 
    #4 AU 5425 0.9837414 
    #5 BA 31 0.9871938 
    #6 BB 99 0.9715991 

    ##Merge SpatialPolygonsDataFrame with other info 
    map_dat <- merge(worldR, datR, by.x="ISO2",by.y="iso") 
    #remove coordinate reference system arguments 
    proj4string(map_dat) <- CRS(as.character(NA)) # from here https://github.com/chrisbrunsdon/getcartr/issues/1 
    world.carto <- quick.carto(map_dat, map_dat$size, blur = 0) 
    #plot(world.carto) #cartogram without anything 
    #spplot size, color 
    my.palette = c("#ff0000", "#ff8000", "#ffff00", "#bfff00","#00ff00") #red, orange, yellow, light green, dark green 
    spplot(world.carto, 'score', col.regions = my.palette, cuts = length(my.palette)-1,main="Choropleth of score and cartogram of size") 

이 당신이 유사한 플롯을 제공해야

나는 급하게 이것을했는데, 그것이 작동하는 경우 알려 주시기 바랍니다.