2015-10-20 16 views
0

我想使用k-medoids聚类地理信息。在考虑地球曲率的同时,我需要集中在纬度,经度和深度上。R中的地理数据上的聚类Shiny

我的最终目标是将数据绘制为地图,并为不同区域使用不同的颜色。这里是绘制和打印数据的现有ggplot(但只包括纬度,经度和不必要的大小),并没有考虑深度或聚类。

pp <- ggplot() + 
geom_polygon(aes(long,lat, group=group), fill="palegreen3", colour="grey60", data=county) + 
geom_polygon(data=states, aes(x=long, y=lat, group = group),colour="royalblue4", fill=NA) + 
annotate("rect", xmin=-84, xmax=-71, ymin=35.5, ymax=43.5, colour="black", size=1, fill="blue", alpha="0.01") + 
geom_point(data=plotdata, size=3, alpha = .7, aes(x=lon, y=lat, color=emw)) + 
theme(plot.background = element_rect(fill = 'grey')) + 
geom_abline(intercept = 3, slope = -.45, color = "grey", size = 1) 

print(pp) 

下面是用于ggplot样本数据集(没有深度或集群):

target_states <- c("pennsylvania", "new york", "new jersey", "virginia", "kentucky","rhode island", 
     "massachusetts","vermont","new hampshire", "delaware", "maryland", "west virginia", 
     "north carolina", "tennessee", "ohio", "connecticut", "district of columbia") 
all_states <- map_data("state") 
county <- map_data("county") 

plotdata <- structure(list(lat = c(50L, -30L, -33L), lon = c(-40L, -30L, -50L), mag = c(3.5, 1.1, 2.3)), .Names = c("lat", "lon", "mag"), class = "data.frame", row.names = c(NA, -3L)) 

任何建议,如何更好地实现这一目标?

回答

0

事实上,你试图在闪闪发亮的事实与实际问题无关,所以我会放下该标签。

您可以使用包geosphere(请参阅distHaversine,请参阅as.dist)计算地理点之间的距离。您可以将生成的距离矩阵从cluster包提供给pam函数以获取您的群集。

或者,您可以将您的坐标转换为三维坐标,如此处所述3D coordinates on a sphere to Latitude and Longitude