映射澳大利亚城市-R空间 [英] Map Australian cities - R spatial

查看:132
本文介绍了映射澳大利亚城市-R空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想画一张澳大利亚地图,并用点表示每个城市. 然后突出显示人口众多(> 1M)的城市

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)

我已经检查了sp软件包,可以在加拿大和其他一些国家使用.但是澳大利亚的细节不存在.是否有一种特殊的方式来获取我们喜欢的国家(城市名称,长,纬度,流行)的数据?

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)?

推荐答案

现在您已经使用world.cities获得了数据,您可以通过几种方式绘制它们

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",]

基本点图

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)

这篇关于映射澳大利亚城市-R空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆