library(leaflet)
## Warning: package 'leaflet' was built under R version 3.5.3
Constants are set for the longitude and lattitude of Area 51 and the maximum deviation from the longitude and latitude of the aliens.
lat_51 <- 37.23433
lng_51 <- -115.80666
const <- 1
Then an alien icon is made and put into a list of 20.
alien_icon <- makeIcon(
iconUrl = 'ET.jpg',
iconWidth = 31*(215/230),
iconHeight= 31,
iconAnchorX = 31 * 215 / 230 / 2,
iconAnchorY = 16
)
icons <- c(NULL, rep(alien_icon, times=20))
A dataframe of 20 aline locations is randomly generated.
df <- data.frame(
lat=c(runif(20, min=lat_51-const, max=lat_51+const)),
lng=c(runif(20, min=lng_51-const, max=lng_51+const))
)
Finally area 51 is located with the standard marker and the aliens are located with their custom markers.
df %>%
leaflet() %>%
addTiles() %>%
addMarkers(icon=icons, popup="You've found ET") %>%
addMarkers(lng=lng_51, lat=lat_51, popup="Area 51")