2012-01-12 7 views
5

एक आकारफाइल को देखते हुए, मैं आकार फ़ाइल में आकार क्षेत्रों के अनुरूप पहचानकर्ताओं का उपयोग करके विषयगत मानचित्रों को प्लॉट करने में सक्षम होने के लिए डेटा फ़ाइल को कैसे आकार और उपयोग कर सकता हूं?अलग-अलग स्रोतों से आकार और डेटा फ़ाइलों का उपयोग कर आर में थीमैटिक मैप्स प्लॉटिंग

#Download English Government Office Network Regions (GOR) from: 
#http://www.sharegeo.ac.uk/handle/10672/50 
tmp_dir = tempdir() 
url_data = "http://www.sharegeo.ac.uk/download/10672/50/English%20Government%20Office%20Network%20Regions%20(GOR).zip" 
zip_file = sprintf("%s/shpfile.zip", tmp_dir) 
download.file(url_data, zip_file) 
unzip(zip_file, exdir = tmp_dir) 

library(maptools) 

#Load in the data file (could this be done from the downloaded zip file directly? 
gor=readShapeSpatial(sprintf('%s/Regions.shp', tmp_dir)) 

#I can plot the shapefile okay... 
plot(gor) 

#and I can use these commands to get a feel for the data... 
summary(gor) 
attributes([email protected]) 
[email protected]$NAME 
#[1] North East    North West    
#[3] Greater London Authority West Midlands   
#[5] Yorkshire and The Humber South West    
#[7] East Midlands   South East    
#[9] East of England   
#9 Levels: East Midlands East of England ... Yorkshire and The Humber 

#download data from http://www.justice.gov.uk/downloads/publications/statistics-and-data/courts-and-sentencing/csq-q3-2011-insolvency-tables.csv 
#insolvency<- read.csv("~/Downloads/csq-q3-2011-insolvency-tables.csv") 
insolvency=read.csv("http://www.justice.gov.uk/downloads/publications/statistics-and-data/courts-and-sentencing/csq-q3-2011-insolvency-tables.csv") 
insolvencygor.2011Q3=subset(insolvency,Time.Period=='2011 Q3' & Geography.Type=='Government office region') 
#tidy the data 
require(gdata) 
insolvencygor.2011Q3=drop.levels(insolvencygor.2011Q3) 

names(insolvencygor.2011Q3) 
#[1] "Time.Period"     "Geography"     
#[3] "Geography.Type"    "Company.Winding.up.Petition" 
#[5] "Creditors.Petition"   "Debtors.Petition" 

levels(insolvencygor.2011Q3$Geography) 
#[1] "East"      "East Midlands"   
#[3] "London"     "North East"    
#[5] "North West"    "South East"    
#[7] "South West"    "Wales"     
#[9] "West Midlands"   "Yorkshire and the Humber" 

#So what next? 

होने कि अब तक, मैं कैसे एक विषयगत/choropleth नक्शा पैदा करने में अगला कदम उठाने करना है, कि रंग प्रत्येक क्षेत्र Debtors.Petition मूल्य के अनुसार, उदाहरण के लिए?

(मैं भी सिर्फ एक संभव पकड़ लिया देखा - पूंजीकरण GOR के स्तर में एक बेमेल है: "यॉर्कशायर और हंबर" और "यॉर्कशायर और हंबर")

+0

ऐसा लगता है [यह SO पोस्ट] (http://stackoverflow.com/questions/1260965/developing-geographic-thematic-maps-with-r) (दाईं ओर-बार में "संबंधित" सूची पर पहला वाला) आपको शेष तरीके से प्राप्त करने में सहायता कर सकता है। –

+0

मैंने इसे देखा, लेकिन पहले कुछ बार दौर को ठीक किया ... तो मुझे क्या करना है: \t gor @ data = merge (insolvencygor.2011Q3, gor @ data, by.x = ' भूगोल ', by.y =' NAME ') साजिश (gor, col = level ([email protected]$ क्रेडिटर्स.पेटिशन)) हालांकि उचित रंग मैपिंग के साथ, और उचित क्षेत्र का नाम मानचित्र (मुझे लगता है कि यह सिर्फ यॉर्क नहीं है और जो मेल नहीं खाता है ...) – psychemedia

+0

क्या आप अपने डेटासेट को एक छोटे से उदाहरण में कम कर सकते हैं जो आपको बताता है? आप इन्हें सेव कमांड का उपयोग करके सहेज सकते हैं और उन्हें एसओ या सर्वर पर अपलोड कर सकते हैं और यहां लिंक पोस्ट कर सकते हैं। इससे बड़ी मात्रा में कोड कम हो जाएगा जो आपके पास बहुत आसान है। –

उत्तर

1

पेड़ों के लिए लकड़ी नहीं देखा है,

#Convert factors to numeric [ http://stackoverflow.com/questions/4798343/convert-factor-to-integer ] 
#There's probably a much better formulaic way of doing this/automating this? 
insolvencygor.2011Q3$Creditors.Petition=as.numeric(levels(insolvencygor.2011Q3$Creditors.Petition))[insolvencygor.2011Q3$Creditors.Petition] 
insolvencygor.2011Q3$Company.Winding.up.Petition=as.numeric(levels(insolvencygor.2011Q3$Company.Winding.up.Petition))[insolvencygor.2011Q3$Company.Winding.up.Petition] 
insolvencygor.2011Q3$Debtors.Petition=as.numeric(levels(insolvencygor.2011Q3$Debtors.Petition))[insolvencygor.2011Q3$Debtors.Petition] 

#Tweak the levels so they match exactly (really should do this via a lookup table of some sort?) 
i2=insolvencygor.2011Q3 
i2c=c('East of England','East Midlands','Greater London Authority','North East','North West','South East','South West','Wales','West Midlands','Yorkshire and The Humber') 
i2$Geography=factor(i2$Geography,labels=i2c) 

#Merge the data with the shapefile 
[email protected]=merge([email protected],i2,by.x='NAME',by.y='Geography') 

#Plot the data using a greyscale 
plot(gor,col=gray([email protected]$Creditors.Petition/max([email protected]$Creditors.Petition))) 

तो क्या इस दृष्टिकोण करता शेपफ़ाइल में संख्यात्मक डेटा विलय, और फिर इसे सीधे साजिश है: अपने ही सवाल का जवाब देने के लिए, यहाँ एक ही रास्ता (प्रश्न में कोड से पर निम्नलिखित कोड) है।

उस ने कहा, डेटा फ़ाइल और आकारफाइल को अलग रखने के लिए क्लीनर तरीका नहीं होगा? (मुझे अभी भी यकीन नहीं है कि यह कैसे करें?)

+0

मुझे नहीं लगता कि यह क्लीनर होगा, और आपको साजिश बनाने के लिए 'सामान्य' और स्थानिक डेटा को गठबंधन करने की आवश्यकता है। –

+0

और मैं आपकी भावना साझा करता हूं कि कोड कम और अधिक बिंदु पर हो सकता है, लेकिन बिना किसी पुनरुत्पादित उदाहरण के प्रदर्शन करना मुश्किल है। –

+0

किस अर्थ में पुनरुत्पादित? प्रश्न में कोड के उपर्युक्त उत्तर कोड को जोड़ना विषयगत मानचित्र उत्पन्न करता है, हालांकि स्वीकार्य रूप से स्क्रिप्ट द्वारा संभाले जाने के बजाय डाउनलोड चरणों को मैन्युअल हस्तक्षेप के रूप में आवश्यक है। – psychemedia

संबंधित मुद्दे