[R-sig-Geo] Colors for factors in leaflet r

Manuel Spínola mspinola10 at gmail.com
Fri Feb 10 16:25:57 CET 2017


Dear list members,

I am trying to add a legend to a leaflet map but I got the following error

data(meuse)
coordinates(meuse) <- ~x+y
proj4string(meuse) <- CRS("+init=epsg:28992")
WGS84 <- CRS("+proj=longlat +ellps=WGS84")
meuse <- spTransform(meuse, WGS84)

pal <- colorFactor(palette = c("red", "blue", "green"), levels = meuse$soil)
meuse$soil
leaflet(meuse) %>%
  addTiles() %>%
  addCircleMarkers(stroke = FALSE, fillOpacity = 1) %>%
  addLegend("topright", color = ~pal(soil), labels=c("Type 1", "Type 2",
"Type 3"), title="Soil type")

Duplicate levels detected
 Show Traceback
Error in addLegend(., "topright", color = ~pal(soil), labels = c("Type 1",
: 'colors' and 'labels' must be of the same length



Best,

Manuel

-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspinola at una.cr <mspinola at una.ac.cr>
mspinola10 at gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río <https://sites.google.com/site/lobitoderio/>
Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list