Với shapefile, làm cách nào để định hình và sử dụng tệp dữ liệu để có thể vẽ bản đồ chuyên đề bằng cách sử dụng mã định danh tương ứng với vùng hình dạng trong shapefile?Vẽ sơ đồ theo chủ đề trong R Sử dụng Shapefile và tập tin dữ liệu từ các nguồn khác nhau
#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?
Có bị đó đến nay, làm thế nào để thực hiện bước tiếp theo trong việc tạo ra một bản đồ chuyên đề/choropleth, mà màu sắc từng vùng theo các giá trị Debtors.Petition, ví dụ?
(Tôi cũng chỉ nhận thấy một Gotcha càng tốt - có một không phù hợp ở các cấp độ GOR hoa: "Yorkshire và Humber" và "Yorkshire và The Humber")
Dường như [bài đăng SO này] (http://stackoverflow.com/questions/1260965/developing-geographic-thematic-maps-with-r) (người đầu tiên trong danh sách "Liên quan" ở phía bên phải thanh) có thể giúp bạn có được phần còn lại của con đường. –
Tôi thấy điều đó, nhưng bỏ lỡ việc sửa chữa vài lần đầu tiên ... Vì vậy, những gì tôi cần làm là một cái gì đó như: \t gor @ data = merge (insolvencygor.2011Q3, gor @ data, by.x = ' Địa lý ', by.y =' NAME ') cốt truyện (gor, col = levels ([email protected]$Creditors.Petition)) mặc dù với ánh xạ màu thích hợp và bản đồ tên vùng thích hợp (tôi nhận thấy nó không chỉ là York và Humberside không phù hợp ...) – psychemedia
Bạn có thể giảm số liệu của mình xuống một ví dụ nhỏ minh họa cho bạn vấn đề không? Bạn có thể lưu chúng bằng cách sử dụng lệnh lưu và tải chúng lên SO hoặc tới máy chủ và đăng liên kết ở đây. Điều này sẽ làm giảm số lượng lớn mã mà bạn có dễ dàng hơn nhiều. –