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

My sample data is as follows

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

My graph as displays like this

enter image description here

Ignore the legend for now. What I want is to have plots for all states. I don't know why it's just South Dakota. Maybe because it's the last one in ABC order?

The counties also confuse me. I'd just use the total aggregate for the whole state (since that's what all the counties add up to), but I'm confused how that would map out and if I need coordinates.

Can someone help me plot? I'd like to use a color scale based on the highest or lowest value (FoodService) per state if possible. IDK why it's just South Dakota.

Dave2e
  • 22,192
  • 18
  • 42
  • 50
  • 1
    In `aes` you are specifying `x = 1, y = 1` that's why it is showing one point only. x should be longitude and y should be latitude. You can calculate centroid of each polygon and then join the data to that. Then use that data for plotting. Please visit [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – UseR10085 Jul 31 '21 at 04:54

1 Answers1

1

As you have not provided any data, I am creating some data and plotting it using the following code

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

UseR10085
  • 7,120
  • 3
  • 24
  • 54