绘制澳大利亚城市地图 - R spatial
Map Australian cities - R spatial
我想画一张澳大利亚地图,用一个点代表每个城市。
然后突出显示人口较多 (>100 万)
的城市
library(sp)
library(maps)
data(canada.cities)
head(canada.cities)
我已经检查了可以为加拿大和其他一些国家/地区完成此操作的 sp 包。但澳大利亚的细节不在那里。有没有一种特殊的方法来获取我们喜欢的国家的数据(城市名称,long,lat,pop)?
现在你有了使用 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)
我想画一张澳大利亚地图,用一个点代表每个城市。 然后突出显示人口较多 (>100 万)
的城市library(sp)
library(maps)
data(canada.cities)
head(canada.cities)
我已经检查了可以为加拿大和其他一些国家/地区完成此操作的 sp 包。但澳大利亚的细节不在那里。有没有一种特殊的方法来获取我们喜欢的国家的数据(城市名称,long,lat,pop)?
现在你有了使用 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)