I would like to cluster geographical information using k-medoids. While accounting for curvature of the earth, I need to cluster on latitude, longitude, and depth.
My ultimate goal is to plot the data as a map, with different colors for different areas. Here is the existing ggplot that plots and prints the data (but only latitude, longitude, and the nonnecessary magnitude), and doesn't take into account depth or the clustering.
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)
Here's a sample dataset used for the ggplot (without depth or clustering):
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))
Any suggestions as to how best to achieve this?