Ggplot error message for shape file st_transform.sfc cannot transform sfc object with missing crs

Hello epi community,

I wrote the following code to produce a plot map using a shapefile in the format of:

Health_Districts__2022_.shx

I was able to import the file with no issues, but when I wrote code to plot the map I received the following error message:

#Plot Points

ggplot(data = LA_county_hospital_data_sf) +
geom_sf()

#Plot health district boundaries

ggplot(data = Health_Districts__2022_) +
geom_sf()

#plot using the health districts map

ggplot(data = Health_Districts__2022_) +
geom_sf()

ggplot() +
geom_sf(data = Health_Districts__2022_, fill = “white”) + # plot the boundaries first, white color
geom_sf(data = LA_county_hospital_data_sf) # plot the points on top of the boundaries

#error message
Error in st_transform.sfc(X[[i]], …) :
cannot transform sfc object with missing crs

What caused this error and how do I fix it?

1 Like

Hi, @carmong

To help you better, could you please share a reproducible example of your data and code?
Check out this link How to Post an R Code Question.

We look forward to helping you

Lucca

1 Like