This project sets out to create a map resource for those who are participating in choir performances in cathedrals in Ireland, Scotland, Wales and England. The resource includes many, though certainly not all, of the cathedrals in these nations. A friendly source created our dataset, which is available at http://www.cathedralchoir.org.uk/imbibit/.
The first step in creating our map is to upload our libraries.
#devtools::install_github('rstudio/leaflet')
#the CRAN leaflet doesn't let you add labels, so if you want to do that run the github install
library(dplyr) #for piping
library(leaflet) #map engine
library(rgdal)
The next step is to import our datasets from the website into R, converting them into R objects.
cathedrals <- read.csv('http://www.cathedralchoir.org.uk/imbibit/imbibit_cathedrals.csv', header = T)
pubs <- read.csv('http://www.cathedralchoir.org.uk/imbibit/imbibit_pubs.csv', header = T)
eateries <- read.csv('http://www.cathedralchoir.org.uk/imbibit/imbibit_eateries.csv', header = T)
It is very important to create just the right icons for this type of resource. One wouldn’t want a casual user to mistakenly visit the wrong type of establishment, an easy mistake to make when visiting multiple establishments in our dataset. We have imported icon from a free icon site.
CathIcon <- makeIcon(
iconUrl = 'church.png',
iconWidth = 20
)
PubIcon <- makeIcon(
iconUrl = 'pub.svg',
iconWidth = 20
)
EatIcon <- makeIcon(
iconUrl = 'restaurant.svg',
iconWidth = 20
)
This step is the construction of the map resource, now that we have all the building blocks. The steps are explained in the comments.
leaflet(data=cathedrals,height=800,width=800) %>%
#this step begins the process, outlining the size of the map box.
addTiles(group = 'OSM (default)') %>%
#Establishes a basemap of OpenStreetMaps. The grouping will be used later.
setView(-4,53.5,6) %>%
#Focuses the map somewhere in Wales, and zoomed so that all our data points will be isible.
addMarkers ( #starts the process of adding the cathedral makers
~Cathedral.Longitude, ~Cathedral.Latitude,
#sometimes lefalet can recognize the variables that represent longitude and latitude. In this case it could not, and we have provided the map with them.
group = 'Cathedrals',
#for layer control
popup=paste (cathedrals$Cathedral.Full.Title, '<br <a href="', cathedrals$Choir.Website,'">', cathedrals$Cathedral.Website, '</a>'),
#Here we build our popup, with the full title and choir website for quick event-checking.
#We run into a problem with missing information here. Not all of the websites are given, so to make sure there isn't a blue text with no link, we provide the text as the link. If there is no link, there will only be a blank space
icon = CathIcon,
#a good, solid icon
label=cathedrals$Cathedral.Full.Title,
labelOptions = labelOptions(noHide = T, opacity=0)
#these are optional labels for churches. At the moment it seems that labels are quite intrusive, with background and a box around them getting in the way of the icons. Increase opacity to see them.
)%>%
addMarkers ( #Now we move on to the pubs
pubs$Pob.Longitude,pubs$Pub.Latitude,
group = 'Pubs',
popup = paste(pubs$Pub.Name, '<br><a href="',pubs$Pub.Website, '">', pubs$Pub.Website, '</a><br>', pubs$Pub.Description), #The popup for the pubs includes the name, website if available (a blank space if not), and a description of the pub if available
icon = PubIcon
) %>%
addMarkers( #our restaurants
eateries$Eatery.Longitude, eateries$Eatery.Latitude,
group = 'Eateries',
popup = paste(eateries$Eatery.Name, '<br><a href="',eateries$Eatery.Website, '">', eateries$Eatery.Website, '</a><br>', eateries$Eatery.Description), #same format
icon = EatIcon) %>%
# Layers control
#And this provides a handy way to use the map resource for multiple purposes. Just looking for the cathedral? Turn the other layers off. Need a restaurant but too many pubs crowding the map? With toggle-able layers, the map becomes easier to manipulate.
addLayersControl(
baseGroups = c('OSM (default)'),
overlayGroups = c("Cathedrals", "Pubs", "Eateries"),
options = layersControlOptions(collapsed = FALSE)
)