I need to map on Shiny leaflet map points based on their type - four types in total with the same marker of a different color.
I checked this:
https://rstudio.github.io/leaflet/markers.html
This looks like my response, but I cannot fix it :( Change color of leaflet marker
This code was shared in the answer
library(dplyr)
library(leaflet)
mutate(quakes, group = cut(mag, breaks = c(0, 5, 6, Inf), labels = c("blue",
"green", "orange"))) -> mydf
### I edit this png file and created my own marker.
### https://raw.githubusercontent.com/lvoogdt/Leaflet.awesome-
markers/master/dist/images/markers-soft.png
quakeIcons <- iconList(blue = makeIcon("/Users/jazzurro/Documents/Stack
Overflow/blue.png", iconWidth = 24, iconHeight =32),
green = makeIcon("/Users/jazzurro/Documents/Stack
Overflow/green.png", iconWidth = 24, iconHeight =32),
orange = makeIcon("/Users/jazzurro/Documents/Stack
Overflow/orange.png", iconWidth = 24, iconHeight =32))
leaflet(data = mydf[1:100,]) %>%
addTiles() %>%
addMarkers(icon = ~quakeIcons[group])
I basically have the same code
# Create our own custom icons
teamIcons <- iconList(
A = makeIcon("C:/Map/Asset 20.png", iconWidth = 18, iconHeight = 18),
B = makeIcon("C:/Map/Asset 21.png", iconWidth = 18, iconHeight = 18),
C = makeIcon("C:/Map/Asset 22.png", iconWidth = 18, iconHeight = 18),
D = makeIcon("C:/Map/Asset 23.png", iconWidth = 18, iconHeight = 18))
data1 <- data %>% mutate(type = factor(data$type), c("A", "B", "C", "D"))
Then I just do
m <- leaflet(data=data) %>%
addProviderTiles(providers$Stamen.TonerLite) %>%
addMarkers(~data1$long, ~data1$lat, icon = ~teamIcons[data1$type], popup
state_popup)
Data for addMarkers is taken from another dataset - data1, not data. When I use awesome icons, it does not create problems. When I use my own icons from the directory, I have an ordinary blue marker on a map.
Invalid subscript type 'logical'