在干净的美国地图上绘制点(50个州)

时间:2017-09-22 15:57:56

标签: r google-maps ggplot2

我想在干净的美国地图上绘制点(即美国地图仅在没有地形或文字的白色背景上)。这是样本数据(我的实际数据有50,000点)。

DATA <- data.frame(Lat=c(47.339374,39.693737, 29.757914, 19.543946,64.668754),
           Long=c(-118.0652,-82.765102,-97.929229,-155.581094,-148.926691),
           State= c("Washington","Ohio","Texas","Hawaii","Alaska") )

我尝试使用地图,但阿拉斯加和夏威夷没有出现,我希望它们包含在地图中。

library(maps)
map("state", interior = FALSE)
map("state", boundary = FALSE, lty = 2, col=8, lwd=0.5, add = TRUE)
title("US map")
points(DATA$Long, DATA$Lat, pch=19, cex=0.5, col= 1:nrow(DATA))

RgoogleMaps绘制谷歌地图顶部的点是一个选项,但背景不是白色,使点很难看到。请指教!

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

library(ggplot2)
library(ggrepel)
library(mapproj)

us <- map_data('world',
                   c('usa', 'canada', "hawaii", "mexico"))
ggplot()+
  geom_polygon(data=us, aes(x=long, y=lat, group = group), colour="grey20", fill="grey80")+
  geom_point(data = DATA, aes(x=Long, y = Lat), color = "red")+
  geom_text_repel(data = DATA, aes(x=Long, y = Lat, label = State), color = "red")+
  coord_map(projection = "mercator", xlim=c(-170, -50))+
  theme_bw()

enter image description here