Map Australian cities - R spatial

穿精又带淫゛_ 提交于 2020-05-08 12:50:13

问题


I want to draw a map of Australia and represent each city as a dot. Then highlight the cities with a high population (>1M)

library(sp)
library(maps)
data(canada.cities)
head(canada.cities)

I have checked the sp package where this can be done for Canada and some other countries. But Australia details are not there. Is there a special way to get the data for a country we like (name of cities, long, lat, pop)?


回答1:


Now you have the data using world.cities, you can plot them a few ways

library(maps)
df <- world.cities[world.cities$country.etc == "Australia",]

Basic plot of points

plot(df[, c("long", "lat")])

on a 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))

On a leaflet map

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)



来源:https://stackoverflow.com/questions/37980290/map-australian-cities-r-spatial

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!