R - 如何使所有数据点在地图中可见

plot_usmap() + 
  geom_point(data = filtered1,aes(x = 1,y = 1,size = FoodServices),color = "red",alpha = 0.25)

我的样本数据如下

County               State            FoodService
Alabama                                    200
Baldwin                AL                   20
Bibb                   AL                  180
.
.
.
For all states and counties

我的图表像这样显示

R - 如何使所有数据点在地图中可见

暂时忽略图例。我想要的是所有州的地块。我不知道为什么它只是南达科他州。也许是因为它是 ABC 顺序中的最后一个?

县也让我感到困惑。我只是使用整个州的总聚合(因为这是所有县的总和),但我很困惑如何绘制以及是否需要坐标。

有人可以帮我作图吗?如果可能,我想使用基于每个州的最高或最低值 (FoodService) 的色标。 IDK 为什么它只是南达科他州

gj856721 回答:R - 如何使所有数据点在地图中可见

由于您没有提供任何数据,我正在创建一些数据并使用以下代码绘制它

library(tidyverse)
library(urbnmapr)
library(sf)

#Download the US shapefile
states_sf <- get_urbn_map(map = "states",sf = TRUE)

#Calculate the centroids of each County
centroids <- st_centroid(states_sf)

#Add some data to the centroids point shapefile
centroids$FoodService <- runif(nrow(states_sf),10,200)

#Plotting using `ggplot2`
ggplot() +
  geom_sf(data = states_sf,fill = "grey",color = "#ffffff",size = 0.25) +
  geom_sf(data = centroids,aes(size = FoodService)) +
  theme_bw()

enter image description here

本文链接:https://www.f2er.com/6660.html

大家都在问