Install and load in leaflet packedge

library("leaflet")

Basic map example:

Load in data

  • I embed a download link for my csv file and images so you can download it and use it as a test run if you need practice. It should work with the code below as long as the directories match to where ever you download the data to.

Download location data HERE

Download icon images HERE

toolik_locations <- read.csv("../Data/Toolik_location.csv") #load in file 

Create the map

This will create a basic map with your site locations marked…

NOTE: popup = ~ Locations adds labels to the markers when you click on them

toolik_locations <- read.csv("../Data/Toolik_location.csv") #load in file 
head(toolik_locations) #inspect file
##               Location   Lat    Long
## 1 Toolik field station 68.63 -149.60
## 2             06MAT_B1 68.62 -149.61
## 3             06MAT_B2 68.62 -149.61
## 4             06MAT_B3 68.62 -149.61
## 5             Pipeline 68.56 -149.49
## 6         South Toolik 68.61 -149.56
leaflet(toolik_locations) %>% 
  addTiles() %>%
  addScaleBar() %>%
  addMarkers(lng = ~Long, lat = ~Lat, popup = ~ Location)

If the markers do not show up:

There seems to be some sort of error on the leaflet side where the regular markers addMarkers do not seem to always be working. If this is the case, try using addCircleMarkers() or addAwesomeMarkers() instead. If you use addAwesomeMarkers() you will need to use this code instead:

awesome <- makeAwesomeIcon(
  icon = "info",
  iconColor = "black",
  markerColor = "blue",
  library = "fa"
)

leaflet(toolik_locations) %>% 
  addTiles() %>%
  addScaleBar() %>%
   addAwesomeMarkers(lng = ~Long, lat = ~Lat, icon = awesome, popup = ~ Location)
  

addCircleMarkers() should give you this:

addAwesomeMarkers() should give you this:

See THIS site for other marker options

You can do lots of cool things to customize your map. For more information on how to do these things and more, check out THIS SITE.

If you figure out how to do different colors for different sites or any other cool customization I would love to see it! I want to assign a different custom icon (the icon images I embedded earlier) to each of my sites but I cant figure out how to do it. So if you do anything similar, please share! :)

Hope you find this helpful!