Map Australian cities - R spatial

前端 未结 1 1834
失恋的感觉
失恋的感觉 2021-01-13 21:43

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(can         


        
相关标签:
1条回答
  • 2021-01-13 22:06

    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)
    

    0 讨论(0)
提交回复
热议问题