Plotting data on shapefile with the same CRS, but things are not lining up as I would expect

13 views Asked by At

I have location and infection data for individuals in several Massachusetts towns. I would like to plot them.

I downloaded the massachusetts with towns shapefile from MassGIS (https://www.mass.gov/info-details/massgis-data-2020-us-census-towns). I assigned it the name massmap

I then made my dataframe into a shapefile. (coordinates in dataframe were in columns 11 and 12 and were in the same format as the data in the massmap file): frogs2023projected <- frogs2023clean |> st_as_sf(coords = c(11,12), crs = 26986) #seemed like 26986 was the correct crs? the others I tried from doing st_crs(massmap) did not plot "correctly" either

I then tried to put them into the same crs with st_transform(), like so: frogs2023projected %>% st_transform(st_crs(massmap))

however when i go to plot with this code (other things i have tried commented out):

ggplot() +
  geom_sf(data = massmap, fill =NA) +
  theme_minimal() +
  #geom_point(data = frogs2023, aes(x = Longitude, y = Latitude)) +
  geom_sf(data = spadefoot2023projected) +
  #stat_sf_coordinates(frogs2023projected, mapping = aes(geometry = geometry)) +
  coord_sf()

i get this: enter image description here

New to plotting data in R and not sure if I am understanding st functions and CRS correctly.

Ive tried inputting different CRS codes and can never get things properly aligned.The points should be plotted on top of southeastern MA and the cape.

0

There are 0 answers