调色板和特定颜色
Palette and also a specific color
是否可以在 nycounties$dimension 的值为 0 时创建使用灰色,其余使用调色板?我该怎么做?我尝试了 if in fill color 但我有一个错误 Error in getMapData(map) : argument "map" is missing, with no default
library(leaflet)
nycounties <- rgdal::readOGR("https://raw.githubusercontent.com/openpolis/geojson-italy/master/geojson/limits_IT_provinces.geojson")
city <- c("Novara", "Milano","Torino","Bari")
dimension <- as.numeric(c("1500", "5000","3000","4600"))
df <- data.frame(city, dimension)
nycounties@data = data.frame(nycounties@data,
df[match(nycounties@data[, "prov_name"],
df[, "city"]),])
pal <- colorNumeric("viridis", NULL)
nycounties$dimension[is.na(nycounties$dimension)] = 0
leaflet(nycounties) %>%
addTiles() %>%
addPolygons(stroke = TRUE, smoothFactor = 0.3, fillOpacity = 1,
fillColor = ~pal(nycounties$dimension), weight = 1, color = "black", label = nycounties$prov_name) %>%
addLegend(pal = pal, values = ~(nycounties$dimension), opacity = 1.0)
library(leaflet)
nycounties <- rgdal::readOGR("https://raw.githubusercontent.com/openpolis/geojson-italy/master/geojson/limits_IT_provinces.geojson")
city <- c("Novara", "Milano","Torino","Bari","Cagliari","Perugia")
dimension <- as.numeric(c("1500", "5000","3000","4600","4500","8604"))
df <- data.frame(city, dimension)
nycounties@data = data.frame(nycounties@data,
df[match(nycounties@data[, "prov_name"],
df[, "city"]),])
nycounties$dimension[is.na(nycounties$dimension)] = 0
pal <- colorNumeric("viridis", domain=c(1,max(nycounties$dimension)))
leaflet(nycounties) %>%
addTiles() %>%
addPolygons(stroke = TRUE, smoothFactor = 0.3, fillOpacity = 1,
fillColor = ~pal(nycounties$dimension), weight = 1, color = "black", label = nycounties$prov_name) %>%
addLegend(pal = pal, values = ~(nycounties$dimension), opacity = 1.0)
是否可以在 nycounties$dimension 的值为 0 时创建使用灰色,其余使用调色板?我该怎么做?我尝试了 if in fill color 但我有一个错误 Error in getMapData(map) : argument "map" is missing, with no default
library(leaflet)
nycounties <- rgdal::readOGR("https://raw.githubusercontent.com/openpolis/geojson-italy/master/geojson/limits_IT_provinces.geojson")
city <- c("Novara", "Milano","Torino","Bari")
dimension <- as.numeric(c("1500", "5000","3000","4600"))
df <- data.frame(city, dimension)
nycounties@data = data.frame(nycounties@data,
df[match(nycounties@data[, "prov_name"],
df[, "city"]),])
pal <- colorNumeric("viridis", NULL)
nycounties$dimension[is.na(nycounties$dimension)] = 0
leaflet(nycounties) %>%
addTiles() %>%
addPolygons(stroke = TRUE, smoothFactor = 0.3, fillOpacity = 1,
fillColor = ~pal(nycounties$dimension), weight = 1, color = "black", label = nycounties$prov_name) %>%
addLegend(pal = pal, values = ~(nycounties$dimension), opacity = 1.0)
library(leaflet)
nycounties <- rgdal::readOGR("https://raw.githubusercontent.com/openpolis/geojson-italy/master/geojson/limits_IT_provinces.geojson")
city <- c("Novara", "Milano","Torino","Bari","Cagliari","Perugia")
dimension <- as.numeric(c("1500", "5000","3000","4600","4500","8604"))
df <- data.frame(city, dimension)
nycounties@data = data.frame(nycounties@data,
df[match(nycounties@data[, "prov_name"],
df[, "city"]),])
nycounties$dimension[is.na(nycounties$dimension)] = 0
pal <- colorNumeric("viridis", domain=c(1,max(nycounties$dimension)))
leaflet(nycounties) %>%
addTiles() %>%
addPolygons(stroke = TRUE, smoothFactor = 0.3, fillOpacity = 1,
fillColor = ~pal(nycounties$dimension), weight = 1, color = "black", label = nycounties$prov_name) %>%
addLegend(pal = pal, values = ~(nycounties$dimension), opacity = 1.0)