I have a set of points (ptns) identified by latitude and longitude that I wish to plot on a map of the US-county-boundaries. I'm using the tidycensus::county_laea
, an "sf" object. Only one point appears on the map and regardless of the coordinates I use the point remains in the same place.
library(tidycensus);library(ggplot2);library(dplyr)
#>
# install.packages("tidycensus")
# census_api_key('census_key', install = T) #access the Census
# readRenviron("~/.Renviron") #run to use now and avoid restart
pnts = tibble(id=c(6012,100157,9434,27458),state=c("NY","FL","CA","OK"),
Lat=c(42.4,24.6,37.3,35.5),Long=c(-76.5,-81.8,-120,-97.5))
ggplot()+geom_sf(data=tidycensus::county_laea) +geom_point(data=pnts,aes(Lat,Long),color="red")
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#ggplotly shows that the coordinates of the point change when I try each point individually, but no its position in the map
plotly::ggplotly(
ggplot()+geom_sf(data=tidycensus::county_laea) +geom_point(data=pnts[1,],aes(Lat,Long),color="red")
)
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
Tried: A ggplot() with two layers: one for a county-level map (geom_sf()), and one for a 4 points that I want to place in the map according to their latitude and longitude (geom_point()). Obtained: A map with only one point displayed. Expected: A map with all points displayed in the correct position.