Add csv data containing coordinates to a map generated from a shp file and obtain information on each point
Solution 1:
You need some flavor of leaflet. You should learn a bit about mapview.
Here this is a small example on Llanes (hoping it is also in Pais Vasco!).
The use of osmdata
is just to get some shops around Llanes.
It should produce what you want. You can start with that then twink it with your data. good luck!
library(sf)
library(osmdata)
library(mapview)
#this will just download node for key = "shop" in Llanes
some_shop_in_Llanes <- osmdata::opq(osmdata::getbb("Llanes spain"),
nodes_only = TRUE) %>%
osmdata::add_osm_feature(key = "shop") %>%
osmdata::osmdata_sf() #keep them in sf format
# some_shop_in_Llanes is a bit more complex object but our shopes are in
# some_shop_in_Lanes$osm_points
# here I get their coords X/Y
just_the_coord <- sf::st_coordinates(some_shop_in_Llanes$osm_points)
# I get plenty of data so I selected only the name and X?Y
shop_with_coords <- cbind(some_shop_in_Llanes$osm_points, just_the_coord) %>%
dplyr::select(name, X, Y)
# then plot it!
mapview(shop_with_coords)
Editing to provide just a data frame with X/Y
# 1. Some shops
shop <- data.frame(X = c(-4.758628, -4.758244, -4.756829, -4.759394, -4.753698,
-4.735330, -4.864548, -4.863816, -4.784694, -4.738924),
Y = c(43.42144, 43.42244, 43.42063, 43.42170, 43.41899,
43.41181, 43.42327, 43.42370, 43.42422, 43.40150),
name = LETTERS[1:10])
# 2. Convert into an sf object
shop_sf <- sf::st_as_sf(shop, coords = c("X", "Y"))
# 2.b editing to add CRS my bad!
shop_sf <- sf::st_set_crs(shop_sf, 4326)
# Plot them thanks to mapview
mapview(shop_sf)