Adding custom markers


I've been using the leaflet package for creating geo-spatial data lately and I've been trying the examples in the leaflet for R website (

Currently, my objective is to add a logo as a custom marker to the map. While I could add the markers given in the examples, I'm unable to add other images in the internet as a possible marker for my map. Why's that so ?

Could you share the code you're trying to use to add the markers? It helps us help you to see what you're working with.

For example, below I've changed the example from the link you gave to use a little picture of an angler fish (note that I've changed the dimensions of the image accordingly, but haven't changed anything else, so you still have the shadow image from the greenLeafIcon example)


leaflet(data = quakes[1:20,]) %>% addTiles() %>%
  addMarkers(~long, ~lat, popup = ~as.character(mag), label = ~as.character(mag))

anglerIcon <- makeIcon(
  iconUrl = "",
  iconWidth = 64, iconHeight = 64,
  iconAnchorX = 22, iconAnchorY = 94,
  shadowUrl = "",
  shadowWidth = 50, shadowHeight = 64,
  shadowAnchorX = 4, shadowAnchorY = 62

leaflet(data = quakes[1:4,]) %>% addTiles() %>%
  addMarkers(~long, ~lat, icon = anglerIcon)

Created on 2019-06-18 by the reprex package (v0.3.0)


Hey Mara. The code worked once I pasted the link of the icons from the imgur website. Thank you !
I initially tried to paste the URL of the images from google images but to no avail.

Here's the code, that's finally working.

newleaf <- makeIcon(
iconUrl = "",
iconWidth = 80, iconHeight = 60,
iconAnchorX = 22, iconAnchorY = 94,
shadowUrl = "",
shadowWidth = 50, shadowHeight = 95,
shadowAnchorX = 2, shadowAnchorY = 100

leaflet(data = quakes[1:20,]) %>% #Subsets 20 rows of the quakes dataset
addTiles() %>% #Adds the default tile for the map
addMarkers(~long, ~lat, icon = newleaf)

The output:

Oh, and that's a Crustle with a Dugtrio, which symbolically represents the boulders and the earthquakes in the Pokemon series. All credits to the imgur website. Thank you !

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.