且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

重叠标签ggmap

更新时间:2023-08-26 21:15:04

调整坐标可能是简单的解决方案,但只有当你有观察结果。一个例子:

Adjusting the coordinates might be the easy solution, but only when you have few observations. An example:

df <- read.table(text="Naam lat lon
Nieuw-Zeelandweg 52.40466 4.80214
Portsmuiden 52.39014 4.78554
Westhavenweg 52.41602 4.82282
Westhavenweg 52.41702 4.82282
Westhavenweg 52.41802 4.82282
Deccaweg 52.40196 4.83910
Coenhavenweg 52.40364 4.86195", header = TRUE, strip.white = TRUE)

require(ggmap)
require(ggplot2)

roads <- get_map(location = c(lon = 4.82824, lat = 52.40738), zoom = 13, 
                 maptype = "roadmap", scale = 2)

ggmap(roads) +
  geom_point(data = df, aes(x=lon, y=lat, fill="red", alpha=0.5, label = df$Naam),
             size=4, shape=21) +
  geom_text(data = df, aes(x = lon, y = lat, label = Naam), 
            size = 3, vjust = 0, hjust = -0.1) +
  guides(fill = FALSE, alpha = FALSE)

结果: