2012-01-12 15 views
5

Şekil dosyası verildiğinde, şekil dosyalarındaki şekil bölgelerine karşılık gelen tanımlayıcıları kullanarak tematik haritaları çizebilmek için bir veri dosyasını nasıl biçimlendirebilir ve kullanabilirim?Tematik Haritaları Çizme R Farklı Biçimlerdeki Şekil Dosyalarını ve Veri Dosyalarını Kullanma

#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? 

kadar, nasıl, örneğin renkler her bölge Debtors.Petition değerine göre o, bir choropleth/tematik harita üreten bir sonraki aşamaya geçmek anlamına var mı yaşıyorsunuz?

(Ben de sadece olası bir gotcha fark - harf GOR seviyelerinde bir uyumsuzluk vardır: "Yorkshire" ve "Yorkshire")

+0

Öyle görünüyor [bu SO post] (http://stackoverflow.com/questions/1260965/developing-geographic-thematic-maps-with-r) (Sağ taraftaki çubuğun üzerindeki "İlgili" listesindeki ilk kısım, yolun geri kalanında size yardımcı olabilir. –

+0

Bunu gördüm, ancak ilk birkaç kez düzeltmeyi kaçırdım ... Yani yapmam gereken şey şu gibi bir şey: \t gor @ data = birleştirme (insolvencygor.2011Q3, gor @ data, by.x = ' Coğrafya ', by.y =' ADI ') arsa (gor, col = seviyeleri ([email protected]$Creditors.Petition)) düzgün bir renk eşleme ve uygun bölge adı haritaları ile (Ben sadece bu sadece Yorks değil ve Humberside bu yanlış eşleşmedir ...) – psychemedia

+0

Veri kümenizi sorununuzu gösteren küçük bir örneğe indirebilir misiniz? Bunları kaydetme komutunu kullanarak kaydedebilir ve bunları SO'ya veya bir sunucuya yükleyebilir ve bağlantıyı buraya gönderebilirsiniz. Bu çok daha kolay olan kod büyük miktarda azaltacaktır. B) shapefiles haritalarda hatlarını oluşturmak için var olduğunu bilerek a) tematik haritalar oluşturmak isteyen ve c) err, işte bu: –

cevap

1

ağaçlar için ağaç görmedim olması,

#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))) 

Peki bu yaklaşım yapar shape içine sayısal veri birleştirme ve ardından doğrudan çizmek geçerli: kendi soruyu cevaplamak için, burada tek yönlü (söz konusu kodundan aşağıdaki kodu) bulunuyor. sözü

, daha temiz bir yoldur veri dosyası tutmak olmaz ve şekil dosyası ayırmak? (Hala bunun nasıl emin değilim?)

+0

Ben daha temiz olacağını düşünmüyorum ve arsa yapmak için 'normal' ve mekansal verileri birleştirmek gerekir. –

+0

Ve kod noktasına daha kısa ve daha fazla olabilir duygu paylaşmak, ancak bir tekrarlanabilir örnek olmadan göstermek zordur. –

+0

Hangi anlamda tekrarlanabilir? Yukarıdaki kodun soruna kodun eklenmesi, tematik haritayı oluşturur, bununla birlikte, indirme adımları, komut dosyası tarafından ele alınmak yerine, manüel müdahale olarak gereklidir. – psychemedia

İlgili konular