I want to create a map with markers that show the position of the customers of an enterprise. In my data I have 23 columns with different information on the customers.
I have a column "type.de.compte" with two non numerical variable that are: optician and ophthalmologist.
And what I'm struggling with is to have two different colors for my markers, red if the costumer is an optician and blue if he is an ophthalmologist.
I'm struggling with that.
Here is what I have for now:
icons1 <- awesomeIcons(
icon = 'ion-ios-body',
iconColor = 'black',
library = 'ion',
markerColor = "blue")
leaflet(data = origAddress) %>% addTiles() %>%
addAwesomeMarkers(~long,~lat,
icon=icons1,
popup=paste(origAddress$Nom.du.compte,
"Ville :"origAddress$Ville,
"Téléphone:"origAddress$Téléphone.principal))
You can create the following named vector in advance:
customer_colors = c("optician"='red',
"opthalmologist"='blue')
# optionally, for any exceptions:
colors[is.na(colors)]="white"
Then you can use the following code, assuming your dataframe is called df
:
colors = customer_colors[df$type.de.compte]
icons1 <- awesomeIcons(
icon = 'ion-ios-body',
iconColor = 'black',
library = 'ion',
markerColor = unname(colors))
Hope this helps!