1
我有一个分成组的一些地图数据,想画一个facet_wrap比例的地图,以适应点FACET_WRAP
这是代码,我到目前为止有:
library(dplyr)
library(ggplot2)
test_points =data.frame(map = c(rep("AAA", 5),rep("BBB", 5),rep("CCC", 5),rep("DDD", 5)),
LAT = c(runif(5, -90, -45), runif(5, -45, 0), runif(5, 0, 45), runif(5, 45, 90)),
LON = c(runif(5, -180, -90), runif(5, -90,0), runif(5, 0, 90), runif(5, 90, 180)))
map_lim = test_points %>%
group_by(map) %>%
summarise(y_min = floor(min(LAT)),
y_max = ceiling(max(LAT)),
x_min = floor(min(LON)),
x_max = ceiling(max(LON)))
worldmap = map_data("world")
ggplot() +
geom_polygon(data = worldmap,
aes(x = long, y = lat, group = group)) +
geom_point(data = test_points,
aes(x = LON, y = LAT, group= map, colour = map)) +
#coord_cartesian(
# ylim=c(map_lim[ map_lim$map==map, 2], map_lim[ map_lim$map==map, 3]),
# xlim=c(map_lim[ map_lim$map==map, 4], map_lim[ map_lim$map==map, 5])
#) +
coord_cartesian(
ylim=c(map_lim$y_min, map_lim$y_max),
xlim=c(map_lim$x_min, map_lim$x_max)
) +
facet_wrap(~ map, scales = "free")
你可以看到我已经尝试了限制坐标的两种方法..既不工作。
我得到的是整个世界......每个都有五点。
是否可以独立缩放每个地图?
尝试使用geom_map而不是geom_polygon –
我试过这个,它似乎没有工作。我也尝试将4个极限参数加入到test_points DF中。这也没有用。 我想我将不得不创建4个单独的地图,然后将它们放在一起在同一页上。 – SteveG
出了什么问题? –