library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.4.4
## -- Attaching packages --------------------------- tidyverse 1.2.1 --
## v ggplot2 3.1.0.9000 v purrr 0.2.5
## v tibble 1.4.2 v dplyr 0.7.6
## v tidyr 0.8.1 v stringr 1.2.0
## v readr 1.1.1 v forcats 0.2.0
## Warning: package 'tibble' was built under R version 3.4.4
## Warning: package 'tidyr' was built under R version 3.4.4
## Warning: package 'purrr' was built under R version 3.4.4
## Warning: package 'dplyr' was built under R version 3.4.4
## -- Conflicts ------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(leaflet)
library(magick)
## Linking to ImageMagick 6.9.9.9
## Enabled features: cairo, freetype, fftw, ghostscript, lcms, pango, rsvg, webp
## Disabled features: fontconfig, x11
library(mapview)
FightersLatLong <- read_csv("C:/Users/Trevor/Documents/School/_previous/RStudio/ufc/FightersLatLong.csv")
## Warning: Missing column names filled in: 'X1' [1]
## Parsed with column specification:
## cols(
## X1 = col_integer(),
## Name = col_character(),
## Birth_Date = col_character(),
## Age = col_integer(),
## Birth_Place = col_character(),
## Lat = col_double(),
## Lon = col_double(),
## Country = col_character(),
## Height = col_integer(),
## Weight = col_integer(),
## Association = col_character(),
## Class = col_character(),
## Fighter_id = col_integer(),
## Url = col_character(),
## NickName = col_character(),
## Feet = col_integer(),
## Inch = col_integer(),
## PhotoURL = col_character()
## )
## Warning: 2 parsing failures.
## row # A tibble: 2 x 5 col row col expected actual file expected <int> <chr> <chr> <chr> <chr> actual 1 1626 Inch an integ~ Miletich Mar~ 'C:/Users/Trevor/Documents/School/_~ file 2 1639 Inch an integ~ Memphis Bad ~ 'C:/Users/Trevor/Documents/School/_~
a1 <- FightersLatLong %>%
filter(!is.na(Lat))
## Warning: package 'bindrcpp' was built under R version 3.4.4
head(a1)
## # A tibble: 6 x 18
## X1 Name Birth_Date Age Birth_Place Lat Lon Country Height
## <int> <chr> <chr> <int> <chr> <dbl> <dbl> <chr> <int>
## 1 253 John~ 9/12/1983 33 Ada, Oklah~ 34.8 -96.7 USA 69
## 2 1166 Jon ~ 7/7/1986 30 Adams, Mas~ 42.6 -73.1 USA 72
## 3 1477 Keit~ 4/15/1958 58 Addison, I~ 41.9 -88.0 USA 71
## 4 1556 Sean~ 12/4/1975 41 Akron, Ohio 41.1 -81.5 USA 70
## 5 2 Dieg~ 12/31/1981 35 Albuquerqu~ 35.1 -107. USA 70
## 6 51 John~ 9/26/1984 32 Albuquerqu~ 35.1 -107. USA 63
## # ... with 9 more variables: Weight <int>, Association <chr>, Class <chr>,
## # Fighter_id <int>, Url <chr>, NickName <chr>, Feet <int>, Inch <int>,
## # PhotoURL <chr>
gloveIcon <- makeIcon(iconUrl = "http://www.mmastore-online.com/media/catalog/product/cache/1/image/600x600/9df78eab33525d08d6e5fb8d27136e95/u/f/ufc_official_fight_gloves_2.png",
iconWidth = 38,
iconHeight = 45,
iconAnchorX = 22,
iconAnchorY = 44)
map1 <- leaflet() %>%
addTiles(group = "OSM") %>%
addProviderTiles("CartoDB", group = "Carto") %>%
addProviderTiles("Esri", group = "Esri") %>%
setView(lat = 39.514288, lng = -96.594997, zoom = 3) %>%
addMarkers(icon = gloveIcon, lat = a1$Lat, lng = a1$Lon,
popup = popupImage(a1$PhotoURL, src = "remote", width = 100, height = 150),
clusterOptions = markerClusterOptions()) %>%
addLayersControl(baseGroups = c("OSM", "Carto", "Esri")) %>%
addMiniMap() %>%
addEasyButton(easyButton(icon="fa-globe",
title="Zoom to Level 3",
onClick=JS("function(btn, map){ map.setZoom(3); }"))) %>%
addMeasure(position = "bottomleft",
primaryLengthUnit = "feet",
secondaryLengthUnit = "miles",
primaryAreaUnit = "acres",
secondaryAreaUnit = "sqmiles",
activeColor = "#3D535D",
completedColor = "#7D4479")
#freezeAtZoom = 5
# addLogo("https://media.giphy.com/media/nAVQpEW0C8NHO/giphy.gif", position = "bottomleft", offset.x = 5, offset.y = 40, width = 100, height = 100)
map1
oceanIcons <- iconList( ship = makeIcon(“ferry-18.png”, “ferry-18@2x.png”, 18, 18), pirate = makeIcon(“danger-24.png”, “danger-24@2x.png”, 24, 24) )
df <- sp::SpatialPointsDataFrame( cbind( (runif(20) - .5) * 10 - 90.620130, # lng (runif(20) - .5) * 3.8 + 25.638077 # lat ), data.frame(type = factor( ifelse(runif(20) > 0.75, “pirate”, “ship”), c(“ship”, “pirate”) )) )
leaflet(df) %>% addTiles() %>% # Select from oceanIcons based on df$type addMarkers(icon = ~oceanIcons[type])