在qmap上为一个国家绘制多条线

Draw multiple lines on qmap for a country

我想像 this 一样映射多个连接,但在更精确的级别(国家/地区)上。为此,我想合并 qmap 包和 link 中使用的包,但没有成功。有人有想法吗?

我已经在尝试此代码,但效果也不佳:

map = qmap(location='Berlin', zoom = 5)
berlin = c(geom_polygon(aes(long,lat,group=group), size = 0.1, colour= "#090D2A",
                 fill="#090D2A", alpha=0.8, data=map))

我收到以下错误: Error: ggplot2 doesn't know how to deal with data of class gg/ggplot

有人知道为什么吗? :-(

该错误告诉您正在将 ggplot 类型的对象传递给 geom_polygon 的数据参数(“data=map”)。但是,geom_polygon 通常需要 data.frame 类型的对象。参见 ?geom_polygon

您可以将此示例作为入门:

library(ggmap)
library(ggplot2)
library(geosphere)
map <- qmap(location='Berlin', zoom = 5)
n <- 50L
m <- matrix(c(
10,53,20,53,
3,47,23,55),ncol=4,byrow=T)
m <- gcIntermediate(m[,1:2],m[,3:4], n = n)
m <- as.data.frame(cbind(do.call(rbind, m), id=rep(seq_along(m), each = n)))
map + 
  theme_minimal() + 
  geom_path(
    aes(lon,lat,group=id), 
    data=m, 
    arrow = arrow(ends="both"))