簡體   English   中英

國家人口的等值線圖

[英]Choropleth Map of State Population

試圖創建一個顯示州人口的等值線圖,同時標記首都城市。 我最初有兩個數據框但是無法將ggplot 1添加到ggplot 2中,因此我將兩個數據框組合在一起,表的一部分如下所示: 在此輸入圖像描述

基本上試圖將這兩個圖像組合在一起: 在此輸入圖像描述

在此輸入圖像描述

我寫過

ggplot(spr, aes(long, lat)) + borders("state") + geom_point() + 
coord_quickmap() +geom_label_repel(aes(label = city), size = 2) + 
geom_polygon(aes(long, lat, group = capital, fill = pcls),color = "grey") +
coord_map("bonne", parameters=45) +ggthemes::theme_map() + 
scale_fill_brewer(palette = "Reds")

但是地圖看起來很近: 在此輸入圖像描述

我認為這是多邊形部分讓我失望,但不知道該怎么做。

您將需要shapefile,或者至少已知邊界將數據映射到。

與前幾天的問題保持一致,您仍然可以使用state scale_fill_brewer設計用於離散變量。 使用scale_fill_gradientn ,指定brewer.pal 根據需要在其中添加capitals圖層。

library(ggplot2)
library(usmap)
library(maps)
library(ggrepel)
library(ggthemes)

us <- map_data("state") # get the data to plot and map data to
data(statepop)
pops <- statepop
pops$full <- tolower(pops$full)

ggplot() + geom_map(data = us, map = us, aes(long, lat, map_id = region), fill = "#ffffff", color = "#ffffff", size = 0.15) +
  geom_map(data = pops, map = us, aes(fill = pop_2015, map_id = full), size = 0.15) +
  coord_map("bonne", parameters=45) +
  scale_fill_gradientn(colors = brewer.pal(9, "Reds")) + #adjust the number as necessary
  borders("state") +
  ggthemes::theme_map()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM