在R / Excel中将多边形转换为纬度和经度

时间:2013-05-23 20:05:52

标签: r map latitude-longitude polygons

我有关于明尼苏达州所有县的数据集,其中一列是它的形状。对于每个县,它看起来像这样:

对于艾特金县:

    <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很新,对谷歌API,HTML等一无所知。我正在尝试使用ggplot2和地图包为明尼苏达州所有县的各个方面创建强度图。有没有办法使用这些坐标来制作一层县,或者我是否需要做其他事情?

这是我到目前为止的代码:

MN地图:

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

任何建议都将不胜感激!

0 个答案:

没有答案