我正在用世界范围的数据生成地图,然后放大到特定的区域。在放大的视图中,我想通过将箭头从框的中心指向外部世界中数据点的位置来显示边界框外还有其他数据点。
注:我不需要它是一个“大圆”路径,只需要墨卡托投影中的XY向量,因为我想这对“正常”图也是有用的。
作为示例,以下是显示数据范围的世界地图:
这是放大的视图,手动添加了洋红色箭头,以显示我想要生成的内容。
下面是我用来生成这两个基本图的代码和数据。我需要一种生成箭头的方法。
require(ggplot2)
te = structure(list(lat = c(33.7399, 32.8571, 50.2214, 36.96263, 33.5835,
33.54557, 47.76147, 48, 59.40289, 35.93411, 32.87962, 38.3241,
50.03844, 37.44, 50.07774, 50.26668, 36.5944), lng = c(-118.37608,
-117.25746, -5.3865, -122.00809, -117.86159, -117.79805, -124.45055,
-126, -146.35157, -122.931472, -117.25285, -123.07331, -5.26339,
25.4, -5.709894, -3.86828, -121.96201)), .Names = c("lat", "lng"
), class = "data.frame", row.names = c(NA, -17L))
all_states = map_data("world")
# world version:
wp = ggplot() +
geom_polygon(data = all_states, aes(x = long, y = lat, group = group), colour = "gray",
fill = "gray") +
coord_cartesian(ylim = c(0, 80), xlim = c(-155, 45)) +
geom_point(data = te, aes(x = lng, y = lat), color = "blue", size = 5,alpha = 0.6)
print(wp)
#states plot
sp = ggplot() +
geom_polygon(data = all_states, aes(x = long, y = lat, group = group), colour = "gray", fill = "gray") +
coord_cartesian(ylim = c(30, 52), xlim = c(-128, -114)) +
geom_point(data = te, aes(x = lng, y = lat), color = "blue", size = 5, alpha = 0.6)
print(sp)
https://stackoverflow.com/questions/30131061
复制相似问题