如何使用来自 KML 数据源的 ggplot2 绘制等值线图或专题图?
KML 示例:https ://dl.dropbox.com/u/1156404/nhs_pct.kml
示例数据:https ://dl.dropbox.com/u/1156404/nhs_dent_stat_pct.csv
这是我到目前为止所得到的:
install.packages("rgdal")
library(rgdal)
library(ggplot2)
fn='nhs_pct.kml'
#Look up the list of layers
ogrListLayers(fn)
#The KML file was originally grabbed from Google Fusion Tables
#There's only one layer...but we still need to identify it
kml=readOGR(fn,layer='Fusiontables folder')
#This seems to work for plotting boundaries:
plot(kml)
#And this:
kk=fortify(kml)
ggplot(kk, aes(x=long, y=lat,group=group))+ geom_polygon()
#Add some data into the mix
nhs <- read.csv("nhs_dent_stat_pct.csv")
kml@data=merge(kml@data,nhs,by.x='Name',by.y='PCT.ONS.CODE')
#I think I can plot against this data using plot()?
plot(kml,col=gray(kml@data$A.30.Sep.2012/100))
#But is that actually doing what I think it's doing?!
#And if so, how can experiment using other colour palettes?
#But the real question is: HOW DO I DO COLOUR PLOTS USING gggplot?
ggplot(kk, aes(x=long, y=lat,group=group)) #+ ????
所以我的问题是:我如何使用例如 kml@data$A.30.Sep.2012 值来为区域着色?
作为一个补充问题:然后我如何在 ggplot 上下文中尝试不同的调色板?