Description is a factor - referring back to question from first day, if it were kept as character, it wouldn’t lend itself to being plotted as category (book, film etc.) and thus being colour-sorted, and used for legend, in the subsequent plot below
library(leaflet)
library(sf)
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(here)
## here() starts at C:/Users/HoJa/Documents/R/usgs-20210727
#Quick-plotting the locations from icebreaker on GoogleEarth to get a kml for input into R
locs<- st_read(here("USGS-DataCarpentryIceBreak.kml"))
## Reading layer `USGS-DataCarpentryIceBreak' from data source
## `C:\Users\HoJa\Documents\R\usgs-20210727\USGS-DataCarpentryIceBreak.kml'
## using driver `KML'
## Simple feature collection with 9 features and 2 fields
## Geometry type: POINT
## Dimension: XYZ
## Bounding box: xmin: -149.4937 ymin: 34.04893 xmax: -2.429015 ymax: 64.20084
## z_range: zmin: 0 zmax: 0
## Geodetic CRS: WGS 84
locs$Description<-c("TV", "Book","TV", "Podcast", "Film", "Film","Film","Film","Book")
locs$Description<-as.factor(locs$Description)
locs<-st_transform(locs, crs=4326)
factorpal <- colorFactor(topo.colors(4), locs$Description)
Mapping it:
m<-leaflet(locs) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addCircleMarkers(label = ~as.character(Name), color=~factorpal(Description), labelOptions = labelOptions(noHide = T)) %>%
addLegend("topright", pal = factorpal, values = locs$Description)
#the resultant map object
m