आर

2012-02-16 5 views
31

में कार्टोग्राम + चोरोप्लेथ नक्शा मैं हाल ही में choropleths का एक गुच्छा बनाने के लिए ggplot2 का उपयोग कर रहा हूं। अगर यह संभव हो गया था एक नक्शा इस के समान (WorldMapper से) बनाने के लिए ggplot2 उपयोग करने के लिए मैं सोच रहा था:आर

enter image description here

यह एक choropleth जहां शेपफ़ाइल बहुभुज रिश्तेदार आबादी की गिनती का प्रतिनिधित्व करने के विकृत कर रहे हैं। मेरा मानना ​​है कि इसे एक कार्टोग्राम कहा जाता है। वे इसे अन्य चर के गुच्छा के साथ करते हैं। Choropleth R Challenge की भावना में, क्या कोई जानता है कि आर का उपयोग करके इसे कैसे किया जाए?

+2

है, तो आप आर पर्यावरण के बाहर कार्ट्राम के लिए [ScapeToad] (http://scapetoad.choros.ch/) को आजमा सकते हैं। – radek

+1

इसके लिए धन्यवाद; स्केपटोड बहुत अच्छा काम करता है और मेरी ज़रूरतों को पूरा करता है। हालांकि, आर –

+4

के भीतर कोई समाधान होने पर मैं प्रश्न छोड़ दूंगा, मैंने आरएचएचटीएस के साथ डी 3-कार्ट्राम को एकीकृत करने पर काम करना शुरू कर दिया था। आपके डेटा की संरचना क्या है? – timelyportfolio

उत्तर

4

cartogrampackage, सीआरएएन पर उपलब्ध, आपके पास रबर शीट विकृति-शैली कार्टोग्राम है।

1

यह काम हो सकता है:

आप FFTW पहले से इंस्टॉल करने की आवश्यकता होगी। Rcartogram and getcartr you will need devtools

यह सुनिश्चित नहीं है कि ggplot2 में इसे कैसे करें, लेकिन यहां एक और विकल्प है।

यहां डाउनलोड और अनजिप करने के बाद, मैं Thematic World Map से एक आकृति फ़ाइल का उपयोग कर रहा हूं, आपको 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") 

यह आपको एक भूखंड इस एक के समान देना चाहिए

मैंने इसे जल्दबाजी में किया, मुझे बताएं कि यह