我想画一张澳大利亚地图,并用点表示每个城市。然后突出显示人口众多(> 1百万)的城市
library(sp)
library(maps)
data(canada.cities)
head(canada.cities)
我已经检查了sp包,可以在加拿大和其他一些国家/地区使用。但是澳大利亚的细节不存在。是否有一种特殊的方式来获取我们喜欢的国家(城市名称,长,纬度,流行)的数据?
现在world.cities
,您可以使用数据了,可以用几种方法绘制它们
library(maps)
df <- world.cities[world.cities$country.etc == "Australia",]
基本点图
plot(df[, c("long", "lat")])
在一个 ggmap
library(ggmap)
myMap <- get_map(location = "Australia", zoom = 4)
ggmap(myMap) +
geom_point(data = df[, c("long","lat", "pop")], aes(x=long, y = lat, colour = pop > 1000000))
在leaflet
地图上
library(leaflet)
## define a palette for hte colour
pal <- colorNumeric(palette = "YlOrRd",
domain = df$pop)
leaflet(data = df) %>%
addTiles() %>%
addCircleMarkers(lat = ~lat, lng = ~long, popup = ~name,
color = ~pal(pop), stroke = FALSE, fillOpacity = 0.6) %>%
addLegend(position = "bottomleft", pal = pal, values = ~pop)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句