我有一个关于明尼苏达州所有县的数据集,其中一列是它的形状。对于每个县,它看起来像这样:
对于艾特金县:
<Polygon><outerBoundaryIs><LinearRing><coordinates>-93.051956,46.15767700000001,0 -93.434006,46.15313,0 -93.43261,46.240253,0 -93.80480900000001,46.23817100000001,0 -93.80933400000001,46.580681,0 -93.77426199999999,46.59050400000001,0 -93.77412400000001,46.802605,0 -93.77500100000002,47.030445,0 -93.058258,47.022362,0 -93.05964600000001,46.766071,0 -93.05208600000002,46.417576,0 -93.051956,46.15767700000001,0</coordinates></LinearRing></outerBoundaryIs></Polygon>
我对 R 相当陌生,对 Google API、HTML 等一无所知。我正在尝试使用 ggplot2 和 maps 包为明尼苏达州所有县的各个方面创建强度图。有没有办法使用这些坐标来制作一层县,还是我需要做其他事情?
这是我到目前为止的代码:
明尼苏达州地图:
library(maps)
library(ggplot2)
all_states <- map_data("state")
mn<-subset(all_states, region %in% c("minnesota"))
p<-ggplot()
p<-p+geom_polygon(data=mn, aes(x=long, y=lat, group=group), colour="black", fill="white")
p
我的计划是修改以下内容以适用于每个县,一旦我得到这些多边形:
dataset <- data.frame(region=states,val=runif(49, 0,1))
us_state_map <- map_data('state')
map_data <- merge(us_state_map, dataset, by='region', all=T)
map_data <- map_data[order(map_data$order), ]
(qplot(long, lat, data=map_data, geom="polygon", group=group, fill=val)
+ theme_bw() + labs(x="", y="", fill="")
+ scale_fill_gradient(low='#EEEEEE', high='darkgreen')
+ opts(title="Title",
legend.position="bottom", legend.direction="horizontal"))
任何建议将不胜感激!