I am using the Tigris package to download shape files with the code,
options(tigris_class = "SF")
While I can easily map polygons
ggplot(data=zctas) +
geom_sf(aes())
I am struggling to create a marker/point instead of a filled polygon (for example, a shape -- like a circle inside a zctas) as the shape file I've pulled down from tigris does not have a lat/long for the x and y AES mapping. The shape file has a "geometry" column, and I am wondering if I can use that?
The documentation here, https://ggplot2.tidyverse.org/reference/ggsf.html
appears to indicate the geom_sf can be used go create points? (I am guessing using the centroid of the zctas' polygon?) but I haven't been able to find an example? Grateful for any resources to identify code that maps points from this Tigris generated shape-file, and or tips and/or alternative approaches.
If I understand correctly what you are trying to achieve, you may just need to transform your data into points with the st_centroid()
function... at the most basic, like this:
ggplot(data=st_centroid(zctas)) +
geom_sf()
Or perhaps:
ggplot(data=st_centroid(st_geometry(zctas))) +
geom_sf()
For more details and examples, see: https://r-spatial.github.io/sf/articles/sf5.html