我有谷歌地图和带有文本标签的坐标列表。当我预览时,标签重叠,因此变得不可读:
library(ggmap)
WPmap <- qmap(c(lon=4.80324, lat=52.40738), zoom = 12, source = "google")
表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))
有没有办法阻止重叠?
你可能会考虑尝试ggrepel https://github.com/slowkow/ggrepel放置标签时不重叠:
library(ggmap)
install.packages("devtools")
devtools::install_github("slowkow/ggrepel")
library(ggrepel)
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)
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),
alpha = 0.5, fill = "red", size = 4, shape = 21
) +
geom_label_repel(
data = df,
aes(x = lon, y = lat, label = df$Naam),
box.padding = unit(2, "lines")
) +
guides(fill = FALSE, alpha = FALSE)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)