Librerías

library(openxlsx)
library(leaflet)
library(htmlwidgets)
library(ggmap)
## Loading required package: ggplot2
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.

Data

This data comes from Coin Hoards of the Roman Empire http://chre.ashmus.ox.ac.uk. Only a selection of Potuguese hoards.

x <- read.csv(url("http://raw.githubusercontent.com/dieza/ancient_coins/master/hoard_export_2020_07_01_140910.csv"),stringsAsFactors = FALSE)

Hoards

In this first map que use two backgrounds, the Stamen Toner (http://maps.stamen.com/toner/#17/39.47755/-0.36188) for current geographic information and the Digital Atlas of Roman and Medieval civilizations for the Roman Roads in red (http://ags.cga.harvard.edu/arcgis/services/darmc/roman/MapServer/WMSServer).

s<-leaflet(data = x[,1:12])%>%addTiles(attribution = 'Calzadas de DARMC.')%>% addProviderTiles(providers$Stamen.Toner) %>% addWMSTiles(
    "http://ags.cga.harvard.edu/arcgis/services/darmc/roman/MapServer/WMSServer",
    layers = "94",
    options = WMSTileOptions(format = "image/png", transparent = TRUE,attribution = "Calzadas de DARMC")
) %>% setView(-10,40,7)%>%
  addMarkers(~longitude, ~latitude, popup = ~as.character(coinCount), label = ~hoardName)
## Warning in validateCoords(lng, lat, funcName): Data contains 2 rows with either
## missing or invalid lat/lon values and will be ignored
s

Clustering

In this second map a cluster option is in place.

t<-leaflet(data = x[,1:12])%>%addTiles(attribution = 'Calzadas de DARMC.')%>% addProviderTiles(providers$Stamen.Toner) %>% addWMSTiles(
    "http://ags.cga.harvard.edu/arcgis/services/darmc/roman/MapServer/WMSServer",
    layers = "94",
    options = WMSTileOptions(format = "image/png", transparent = TRUE)
) %>%
  addMarkers(~longitude, ~latitude, popup = ~as.character(coinCount), label = ~hoardName,clusterOptions = markerClusterOptions())
## Warning in validateCoords(lng, lat, funcName): Data contains 2 rows with either
## missing or invalid lat/lon values and will be ignored
t

Icons

Now we’re going to customize the icons. In the first vector we can choose the color. Adding a column with the colors to the data, each treasure, will be displayed in the corresponding color (i.e First century= red, sedond=blue)

colores<-c("blue","red","green")
icons <- awesomeIcons(
  icon = 'ios-close',
  iconColor = 'black',
  library = 'ion',
  markerColor = colores
)

Alternative markers

Once we have the Icons, we can see the results.

u<-leaflet(data = x[,1:12])%>%addTiles(attribution = 'Calzadas de DARMC.')%>% addProviderTiles(providers$Stamen.Toner) %>% addWMSTiles(
    "http://ags.cga.harvard.edu/arcgis/services/darmc/roman/MapServer/WMSServer",
    layers = "94",
    options = WMSTileOptions(format = "image/png", transparent = TRUE)
) %>%
  addAwesomeMarkers(~longitude, ~latitude, popup = ~as.character(coinCount), label = ~hoardName,clusterOptions = markerClusterOptions(),icon=icons)
## Warning in validateCoords(lng, lat, funcName): Data contains 2 rows with either
## missing or invalid lat/lon values and will be ignored
u

Customize icons with images

In this example we use a gold coin and a silver one, the gold coin represents hoards with 100 or more coins, the silver the opposite. In the same way, a link to a particular image of the hoard in the data will display it. (x$link)

BalbinusIcons <- icons(
    iconUrl = ifelse(x$coinCount < 100,
                     "https://i.servimg.com/u/f64/13/94/51/80/sin_no11.png",
                     "https://i.servimg.com/u/f64/13/94/51/80/sin_no17.png"
    ),
    iconWidth = 25,
    iconHeight = 25,
    #iconAnchorX = 22, iconAnchorY = 94,
    #shadowUrl = "http://ikmk.uni-freiburg.de/image/ID4943/rs_opt.jpg",
    #shadowWidth = 50, shadowHeight = 64,
    #shadowAnchorX = 4, shadowAnchorY = 62
)

Test of customize icons

v<-leaflet(data = x[,1:12])%>%addTiles(attribution = 'Calzadas de DARMC.')%>% addProviderTiles(providers$Stamen.Toner) %>% addWMSTiles(
    "http://ags.cga.harvard.edu/arcgis/services/darmc/roman/MapServer/WMSServer",
    layers = "94",
    options = WMSTileOptions(format = "image/png", transparent = TRUE)
) %>%
  addMarkers(~longitude, ~latitude, popup = ~as.character(coinCount), label = ~hoardName,icon=BalbinusIcons)
## Warning in validateCoords(lng, lat, funcName): Data contains 2 rows with either
## missing or invalid lat/lon values and will be ignored
v