重叠标签ggmap [英] Overlapping labels ggmap

查看:129
本文介绍了重叠标签ggmap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有Google地图和带有文本标签的坐标列表。当我预览这些时,标签会重叠并因此变得不可读:

I have the Google map and a list of coordinates with a text label. When I preview this, the labels overlap and thus become unreadable:

library(ggmap)
WPmap <- qmap(c(lon=4.80324, lat=52.40738), zoom = 12,  source = "google")

table kaart_rtw:

table kaart_rtw:

              Naam      lat     lon
1 Nieuw-Zeelandweg 52.40466 4.80214
2      Portsmuiden 52.39014 4.78554
3     Westhavenweg 52.41602 4.82282
4     Westhavenweg 52.41702 4.82282
5     Westhavenweg 52.41802 4.82282
6         Deccaweg 52.40196 4.83910
7     Coenhavenweg 52.40364 4.86195 

AmsterdamMap + geom_text(data = kaart_rtw, aes(label = kaart_rtw$Naam, x = X, y = Y)) 

有没有办法阻止重叠?

推荐答案

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

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)

结果:

这篇关于重叠标签ggmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆