I'm new to programming in R and I want to make an interactive map from two files, one is a .shp that you can download from here: https://www.ine.es/ss/Satellite?L=es_ES&c=Page&cid=1259952026632&p=1259952026632&pagename=ProductosYServicios%2FPYSLayout (just select 2021 year and go and its download), in which there are many polygons. And then I have a csv with store characterization data (it contains 2 LON and LAT fields).
To start doing all this I would like to filter the .shp file for each different value in the NCA field (Ex: 1 map for Basque Country, another for Madrid, another for Barcelona ...).
All this without losing the geometric properties since if I lose them then I can't represent them graphically (or maybe I can and I don't know, if so, let me know and I will be very grateful).
He probado con el siguiente codigo:
# Load the libraries
pacman::p_load(leaflet, leaflet.extras, mapview, rworldxtra, rgdal,raster, sf, tidyverse, readr, ggthemes)
# Load the .shp file in spdf format.
myspdf = readOGR(getwd(), layer = "SECC_CE_20210101")
#Filter
PV = myspdf %>% filter(NCA == "País Vasco") # Dont work
PV2 = myspdf[myspdf$NCA == "País Vasco"] # Dont work
When I load the shp file and save it in the variable myspdf, I can visualize something like this: https://ibb.co/mywDd6p
in which if I do myspdf@data I access the data (where is the NCA field where I want to filter)
So when I try to filter like this:
PV = myspdf %>% filter(NCA == "País Vasco") # Dont work
PV2 = myspdf[myspdf$NCA == "País Vasco"] # Dont work
It returns this to me this: https://ibb.co/VDYdByq, with the rows completely empty, and what I would like to obtain is the same format but with about 1700 rows x 18 columns and with the geometric properties as well.
Another question I have is that when I read the .shp file as sf, one more column is added with the geometry and inside are the coordinates stored in lists, like that: https://ibb.co/M1Fn8K5, I can easily filter it but I don't know how to represent it graphically (leaflet or mapview...) so that You can see the polygons of NCA = 'Basque Country', could someone give me an example with this? I would be enormously grateful