My First Leaflet Map

Loading the leaflet package

library(leaflet)
## Warning: package 'leaflet' was built under R version 4.4.2

Code for Creating the Map

First step involved creating a dataframe with the latitude, longitude, and popup text for the Johns Hopkins University campus locations within Baltimore

markerdata <- data.frame(
  lat = c(39.32745320436845, 39.32853784249999, 39.29701442979074, 39.28527622200511),
  lng = c(-76.61957968999596, -76.60013308512083, -76.61473081696388, -76.60106405692291),
  popup = c("Johns Hopkins University Homewood Campus", 
            "Johns Hopkins East Baltimore Campus", 
            "Peabody Institute of The Johns Hopkins University", 
            "Johns Hopkins Carey Business School"))

Next step is creating the map using leaflet function, followed by adding tiles and markers onto the map created.

my_map <- leaflet() %>%
  addTiles() %>%
  addMarkers(data = markerdata, popup=~popup)
## Assuming "lng" and "lat" are longitude and latitude, respectively

Interactive Map

The created interactive map using leaflet is as follows:

The blue markers indicates the locations of the different Johns Hopkins University Campuses within Baltimore, Maryland, United States of America