Using the UK map I want to display a list of locations. Can anyone help me how I can display the name of the location pinned on the map at the same time with multiple location? The names are
Using google maps I identified the following positions and not the name. The map also needs to visualise locations from Scotland to Wales But how can this be done with R? Hoe can I use the GB map and show the name of the different projects?
CodePudding user response:
You can do this using the leaflet package. I started creating a data frame with the information you provided, including the geolocation (from Google map).
landmarks <- data.frame(name = c('Dinorwig', 'Ffestiniog', 'Crauchan', 'Foyers',
'Glyn Rhonwy', 'Coire Glas', 'Glenmuckloch',
'Red John Pumped Storage'),
label = c('Elidir Fawr mountain, in Dinorwig, Llanberis, in nort Wales',
'Near Ffestiniog, in Gwynedd',
'In Argyll and Bute, Scotland',
'Located on the southeast shore of Loch Ness',
'In Llangeris, North Wales, UK',
'On the shores of Loch Lochy near Invergarry',
'Near Kirkconnel in South-West Scotland',
'South-west of Inverness in the Highland region of Scotland'),
lat = c(53.1335649, 52.9844151, 56.4284862, 57.2555948, 53.1247189,
56.95413, 55.3874814, 57.4680376),
lng = c(-4.1251246, -3.9886801, -5.1347352, -4.4998928, -4.13825,
-4.9860297, -4.0103508, -4.256877))
Then you create the map you specified using the following code:
leaflet(landmarks) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
setView(lat = 54.757715, lng = -7.2327563, 5) %>%
addMarkers(lng = ~lng,
lat = ~lat,
label = ~name,
popup = ~label,
labelOptions = labelOptions(noHide = TRUE))
You can read more about the leaflet package here