1

I am trying to make a leaflet map in R with custom markers for a categorical variable. I used the example at https://rstudio.github.io/leaflet/markers.html as a starting point, but as it uses a numerical variable I adapted as follows:

 logos <- iconList(
 LA = makeIcon("~/mydata/la_logo.png","la_logo-15@2x.png", 15, 15),
 CO = makeIcon("~/mydata/co_logo.jpg","co_logo-15@2x.png", 15,15),
 CF = makeIcon("~/mydata/cf_logo.png","cf_logo-15@2x.png", 15,15),
 NN = makeIcon("~/mydata/nn_logo.png","nn_logo-15@2x.png", 15,15)
 )

leaflet(data) %>%
 addTiles() %>%
 addProviderTiles("CartoDB.Positron") %>%
 addMarkers(icon = ~logos[var]
 )

In data, the variable var has the values "LA", "CO", "CF" and "NN" and lat and lon (latitude and longitude respectively).

My map shows as follows:enter image description here

I have verified that the images are in the url declared. Any ideas? thanks

COLO
  • 1,024
  • 16
  • 28
  • your questions is unclear to me, what is your desired output? – Cyrus Mohammadian Sep 14 '16 at 16:43
  • My intention is to show each ocurrence of the variable "var" with the correspondent logo (image) in the map. In the dataframe each row has values for var, lat and long. var has 4 posible values (LA, CF, CO, NN) and there are several ocurrences of each one, but with different lat and lon. – COLO Sep 14 '16 at 17:00
  • please provide a url link to your icons so we can reproduce and provide some reproducible data if you're seeking help on SO – Cyrus Mohammadian Sep 14 '16 at 17:03
  • logos <- iconList( LA = makeIcon("http://grupomasmasegosa.com/wp-content/uploads/2014/07/hyundai.jpg", "la_logo-15@2x.png", 15, 15), CO = makeIcon("http://grupomasmasegosa.com/wp-content/uploads/2014/07/jeep-logo-icono.png", "co_logo-15@2x.png", 15,15), CF = makeIcon("http://grupomasmasegosa.com/wp-content/uploads/2014/07/kia-motors.png", "cf_logo-15@2x.png", 15,15), NN = makeIcon("http://grupomasmasegosa.com/wp-content/uploads/2014/07/chevrolet-logo.png", "nn_logo-15@2x.png", 15,15) ) – COLO Sep 14 '16 at 17:28
  • all the links you've posted are 404 errors... – Cyrus Mohammadian Sep 14 '16 at 17:30
  • Sorry. I was trying to include full code. here are the links. http://grupomasmasegosa.com/wp-content/uploads/2014/07/hyundai.jpg http://grupomasmasegosa.com/wp-content/uploads/2014/07/kia-motors.png http://grupomasmasegosa.com/wp-content/uploads/2014/07/jeep-logo-icono.png http://grupomasmasegosa.com/wp-content/uploads/2014/07/chevrolet-logo.png – COLO Sep 14 '16 at 17:31
  • and your data.... – Cyrus Mohammadian Sep 14 '16 at 17:33
  • var lat lon 1: CO-54.81790 -68.33530 2: CF -54.81478 -68.32578 3: LA -54.81330 -68.32702 4: LA -54.80924 -68.31342 5: LA -54.80407 -68.30217 6: LA -54.79826 -68.27745 7: LA -54.50444 -67.18861 8: NN -53.79251 -67.72149 9: LA -53.78630 -67.70084 10: CF -53.78498 -67.70316 11: LA -53.77885 -67.71814 12: CF -53.77372 -67.72155 13: CO-53.76949 -67.71694 14: LA -51.64111 -69.22923 15: LA -51.63866 -69.22013 16: LA -51.63544 -69.20936 17: LA -51.63219 -69.19812 18: NN-51.62891 -69.23756 19: CF -51.62722 -69.24734 – COLO Sep 14 '16 at 17:35
  • thats not a reproducible example! How am I suppose to use that! see [here](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for help. You're making it really hard for us to help you. Please follow the SO etiquette... – Cyrus Mohammadian Sep 14 '16 at 17:36

0 Answers0