是否可以使用ggplot在地图上覆盖散点图



我想画一张法国各省(即法国的地区)的地图和地图上的plot point。我使用ggplot2来绘制地图,但当我想在地图上添加点时,R返回一个错误,说它找不到"组"。

library("ggplot2")
library("ggmap")
# load the contour of French departements
wg  <- read.csv("data/departements.csv")
metropoles  <- c("Paris", "Rennes", "Rouen", "Lille", "Marseille")
geo  <- geocode(metropoles)
met  <- data.frame(ville = metropoles, geo)
map  <- ggplot(data = wg, aes(x = long, y = lat, group = group)) + 
geom_polygon() + 
scale_x_continuous(limits = c(-7,10)) + 
scale_y_continuous(limits = c(40,53)) + 
coord_map() + 
theme(axis.text = element_blank(), axis.title = element_blank()) 
map + geom_point(data = met, aes(x = lon, y = lat))

对于复制,您可以在这里找到原始数据,在这里找到R程序

@Roland有很好的答案。问题是我把group定义为一般参数。

ggplot() + 
  geom_polygon(data = wg, aes(x = long, y = lat, group = group)) + 
  scale_x_continuous(limits = c(-7,10)) + 
  scale_y_continuous(limits = c(40,53)) + 
  coord_map() + 
  theme(axis.text = element_blank(), axis.title = element_blank()) 
  geom_point(data = met, aes(x = lon, y = lat))

最新更新