Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a #343

Open
acookpb opened this issue Jan 11, 2023 · 0 comments
Open

a #343

acookpb opened this issue Jan 11, 2023 · 0 comments

Comments

@acookpb
Copy link

acookpb commented Jan 11, 2023

Reproducible Example

I wonder if I've got something wrong here. I'm using this polygon to make CA counties, reading it in as an sf object, converting it to SpatialPolygonsDataFrame to solve alignment issues with the basemap, but cannot fill the polygons based on the "Freq" column, which contains integers in this example. I receive the error 'object not found'

reprex::reprex({
library(sf)
library(ggmap)
Counties.sf <- read_sf("CA_Counties_TIGER2016.shp") #read in shapefile from WD as an sf object
Counties.sf$Freq <- sample(10, size=nrow(Counties.sf), replace=TRUE) #assign random #s 1-10 to each county
Counties.sf <- st_transform(Counties.sf, 4326) #set correct CRS
bbox.sf<-unname(st_bbox(Counties.sf)) #create bbox for basemap 
my.stamen<- get_stamenmap(bbox=bbox.sf, maptype='terrain-background', zoom=8) #call basemap here
Counties.sp<-as_Spatial(Counties.sf) #converting data type to avoid poor alignment with geom_sf
ggmap(my.stamen)+
  geom_polygon(data=Counties.sp, aes(x=long, y=lat, group=group, fill=factor(Freq)))
#map will not run, does not recognize the Freq attribute
}, si = TRUE)
@acookpb acookpb changed the title Unable to code map via "fill=" in aes() function with sp objects a Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant