I have successfully managed to recreate the drive time polygon in R using This Example Post
The above post only deals with ONE single polygon with isochrones
Problem - I want to plot MULTIPLE drive time polygons on 5 different map points
I have managed to do this in a VERY laborious fashion by creating 5 seperate isochrones, and then adding 5 polygons to my Leaflet Map
#Preparing multiple dependancies----
packages <- c("readxl","dplyr","leaflet","htmltools", "sp", "osrm")
install.packages(packages)
lapply(packages, library,character.only=TRUE)
###
#Loading in Locations----
Location <- read_excel("filepath.xlsx", sheet=1)
###
#Extract Lon and Lat and create spatial dataframe
xy <- Location[, c(3,4)]
spatialdf <- SpatialPointsDataFrame(coords = xy, data = Location, proj4string = CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"))
class(spatialdf)
#Create Isochrone points
iso1 <- osrmIsochrone(loc = c(-2.3827439,53.425705), breaks = seq(from = 0, to = 60, by = 5))
iso2 <- osrmIsochrone(loc = c(-0.85074928,51.325871), breaks = seq(from = 0, to = 60, by = 5))
iso3 <- osrmIsochrone(loc = c(-2.939367,51.570344), breaks = seq(from = 0, to = 60, by = 5))
iso4 <- osrmIsochrone(loc = c(-3.9868026,55.823102), breaks = seq(from = 0, to = 60, by = 5))
iso5 <- osrmIsochrone(loc = c(-0.92104073,53.709006), breaks = seq(from = 0, to = 60, by = 5))
#Create Drive Time Interval descriptions
iso1#data$drive_times <- factor(paste(iso1#data$min, "to", iso1#data$max, "mins"))
iso2#data$drive_times <- factor(paste(iso2#data$min, "to", iso2#data$max, "mins"))
iso3#data$drive_times <- factor(paste(iso3#data$min, "to", iso3#data$max, "mins"))
iso4#data$drive_times <- factor(paste(iso4#data$min, "to", iso4#data$max, "mins"))
iso5#data$drive_times <- factor(paste(iso5#data$min, "to", iso5#data$max, "mins"))
#Create Colour Palette for each time interval
factPal1 <- colorFactor(rev(heat.colors(12)), iso1#data$drive_times)
factPal2 <- colorFactor(rev(heat.colors(12)), iso2#data$drive_times)
factPal3 <- colorFactor(rev(heat.colors(12)), iso3#data$drive_times)
factPal4 <- colorFactor(rev(heat.colors(12)), iso4#data$drive_times)
factPal5 <- colorFactor(rev(heat.colors(12)), iso5#data$drive_times)
#Draw Map
leaflet()%>%
addProviderTiles("CartoDB.Positron", group="Greyscale")%>%
addMarkers(data=spatialdf,lng=spatialdf$Longitude, lat=spatialdf$Latitude, popup = htmlEscape(~`Locate`))%>%
addPolygons(fill = TRUE, stroke = TRUE, color = "black",fillColor = ~factPal1(iso1#data$drive_times), weight = 0.5, fillOpacity = 0.2, data=iso1, popup = iso1#data$drive_times, group = "Drive Time")%>%
addPolygons(fill = TRUE, stroke = TRUE, color = "black",fillColor = ~factPal2(iso2#data$drive_times), weight = 0.5, fillOpacity = 0.2, data=iso2, popup = iso2#data$drive_times, group = "Drive Time")%>%
addPolygons(fill = TRUE, stroke = TRUE, color = "black",fillColor = ~factPal3(iso3#data$drive_times), weight = 0.5, fillOpacity = 0.2, data=iso3, popup = iso3#data$drive_times, group = "Drive Time")%>%
addPolygons(fill = TRUE, stroke = TRUE, color = "black",fillColor = ~factPal4(iso4#data$drive_times), weight = 0.5, fillOpacity = 0.2, data=iso4, popup = iso4#data$drive_times, group = "Drive Time")%>%
addPolygons(fill = TRUE, stroke = TRUE, color = "black",fillColor = ~factPal5(iso5#data$drive_times), weight = 0.5, fillOpacity = 0.2, data=iso5, popup = iso5#data$drive_times, group = "Drive Time")%>%
addLegend("bottomright", pal = factPal1, values = iso1#data$drive_times, title = "Drive Time")
Not sure why i cannot just refer to the Spatial dataframe that i made ? like this...
iso <- osrmIsochrone(loc = c(spatialdf$Longitude,spatialdf$Latitude), breaks = seq(from = 0, to = 60, by = 5))
This gives me the error: break values do not fit the raster values
and then just use 1 polygon to map all of them? like this...
leaflet()%>%
addProviderTiles("CartoDB.Positron", group="Greyscale")%>%
addMarkers(data=spatialdf,lng=spatialdf$Longitude, lat=spatialdf$Latitude, popup = htmlEscape(~`Locate`))%>%
addPolygons(fill = TRUE, stroke = TRUE, color = "black",fillColor = ~factPal(iso#data$drive_times), weight = 0.5, fillOpacity = 0.2, data=iso, popup = iso#data$drive_times, group = "Drive Time")%>%
addLegend("bottomright", pal = factPal, values = iso#data$drive_times, title = "Drive Time")
Consider a DRY-er (i.e., Don't Repeat Yourself) approach by building a list of items and then iterate through the piping chain:
# LIST OF COORDS
loc_list <- list(c(-2.3827439, 53.425705), c(-0.85074928, 51.325871),
c(-2.939367,51.570344), c(-3.9868026, 55.823102),
c(-0.92104073, 53.709006))
isoc_items <- lapply(loc_list, function(i) {
iso <- osrmIsochrone(loc = i, breaks = seq(from = 0, to = 60, by = 5))
iso#data$drive_times <- factor(paste(iso#data$min, "to", iso#data$max, "mins"))
# NAMED LIST OF TWO ITEMS
list(iso = iso, factPal = colorFactor(rev(heat.colors(12)), iso#data$drive_times))
})
leaflet()%>%
addProviderTiles("CartoDB.Positron", group="Greyscale")%>%
addMarkers(data = spatialdf, lng = spatialdf$Longitude,
lat = spatialdf$Latitude, popup = htmlEscape(~`Locate`))%>%
# ITERATE TO ADD POLYGONS
for (item in isoc_items) {
addPolygons(fill = TRUE, stroke = TRUE, color = "black",
fillColor = ~item$factPal(item$iso#data$drive_times),
weight = 0.5, fillOpacity = 0.2, data = item$iso,
popup = item$iso#data$drive_times, group = "Drive Time")%>%
}
addLegend("bottomright", pal = isoc_items[[1]]$factPal,
values = isoc_items[[1]]$iso#data$drive_times, title = "Drive Time")
#Parfait has a good use of lapply that I would keep, so I won't recreate it for my answer. For your question of only looking to refer to one spatial polygon dataframe in your call to addPolygon you can use rbind once they are created. Note this only uses one colorFactor set.
#Create Isochrone points
iso1 <- osrmIsochrone(loc = c(-2.3827439,53.425705), breaks = seq(from = 0, to = 60, by = 5))
iso2 <- osrmIsochrone(loc = c(-0.85074928,51.325871), breaks = seq(from = 0, to = 60, by = 5))
iso3 <- osrmIsochrone(loc = c(-2.939367,51.570344), breaks = seq(from = 0, to = 60, by = 5))
iso4 <- osrmIsochrone(loc = c(-3.9868026,55.823102), breaks = seq(from = 0, to = 60, by = 5))
iso5 <- osrmIsochrone(loc = c(-0.92104073,53.709006), breaks = seq(from = 0, to = 60, by = 5))
iso <- rbind(iso1, iso2,iso3,iso4,iso5)
#Create Drive Time Interval descriptions
iso#data$drive_times <- factor(paste(iso#data$min, "to", iso#data$max, "mins"))
#Create Colour Palette for each time interval
factPal <- colorFactor(rev(heat.colors(12)), iso#data$drive_times)
#Draw Map
leaflet()%>%
addProviderTiles("CartoDB.Positron", group="Greyscale")%>%
# addMarkers(data=spatialdf,lng=spatialdf$Longitude, lat=spatialdf$Latitude, popup = htmlEscape(~`Locate`))%>%
addPolygons(fill = TRUE, stroke = TRUE, color = "black",fillColor = ~factPal(iso#data$drive_times), weight = 0.5, fillOpacity = 0.2, data=iso, popup = iso#data$drive_times, group = "Drive Time") %>%
addLegend("bottomright", pal = factPal, values = iso#data$drive_times, title = "Drive Time")
Related
I would like to ask how to calculate number of point that are in some region when we have longtitue and latitude variables of point and polygon of country and its regions.
I provided example below:
I would like to calculate how many point are in what regions (including zero when there is no point) and than add this variables to data2#data object so one can use count measures to fill each regions polygons.
library(leaflet)
library(tidyverse)
set.seed(101)
URL2 <- "https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_FRA_2_sp.rds"
data2 <- readRDS(url(URL2))
URL3 <- "https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_ESP_2_sp.rds"
data3 <- readRDS(url(URL3))
URL4 <- "https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_PRT_2_sp.rds"
data4 <- readRDS(url(URL4))
URL5 <- "https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_GBR_2_sp.rds"
data5 <- readRDS(url(URL5))
random_long_lat <-
data.frame(
long = sample(runif(300, min = -2.5, max = 15.99), replace = F),
lat = sample(runif(300, min = 42.69, max = 59.75), replace = F)
)
all <- rbind(data2, data3, data4, data5)
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data=all, stroke = TRUE, color = "black", weight="", smoothFactor = 0.95,
fill = F) %>%
addCircles(lng = random_long_lat$long, lat = random_long_lat$lat)
# Here add new variable called count, that would count how many point are in the region
all#data
I would like the result so one can calculate something like this:
all#data <-
all#data %>%
mutate(counts = rnorm(nrow(all), 100, sd = 20))
cuts <- c(0, 5, 20, 40, 80, 150, max(all#data$counts))
cuts <- colorBin("Greens", domain = all$counts, bins = cuts)
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data=all, stroke = TRUE, color = "white", weight="", smoothFactor = 0.95,
fillOpacity = 0.65, fillColor = ~cuts(all$counts)) %>%
addLegend(pal = cuts,
values = all$counts,
labFormat = labelFormat(suffix = " "),
opacity = 0.85, title = "How many point were counted in each region", position = "topright")
however I dont know is it posible to calculate number of point in each regions having just coordinances?
If you transform the points and France polygons to sf objects, you can use st_intersects() to count the number of points in each polygon.
Note that I updated your sample points so that each quintile break in cuts is unique. With your original data, the first three quintiles were just 0 so the coloring in the leaflet map didn't work.
new sample data
library(leaflet)
library(tidyverse)
set.seed(101)
URL2 <- "https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_FRA_2_sp.rds"
data2 <- readRDS(url(URL2))
random_long_lat <-
data.frame(
long = sample(runif(1000, min = -2.5, max = 5.99), replace = F),
lat = sample(runif(1000, min = 42.69, max = 49.75), replace = F)
)
make sf objects and count points in polygons
library(sf)
data_sf <- data2 %>% st_as_sf()
random_long_lat_sf <- random_long_lat %>%
st_as_sf(coords = c("long", "lat"), crs = 4326)
data_sf_summary <- data_sf %>%
mutate(counts = lengths(st_intersects(., random_long_lat_sf)))
define breaks for legend and draw map
cuts <- quantile(data_sf_summary$counts, probs = seq(0, 1, 0.2))
cuts <- colorBin("Greens", domain = data_sf_summary$counts, bins = cuts)
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data=data_sf_summary, stroke = TRUE, color = "white", weight="", smoothFactor = 0.95,
fillOpacity = 0.65, fillColor = ~cuts(data_sf_summary$counts)) %>%
addLegend(pal = cuts,
values = data_sf_summary$hdp,
labFormat = labelFormat(suffix = " "),
opacity = 0.85, title = "How many point were counted in each region", position = "topright")
Also note that tmap package, which lets you switch between static and interactive maps using the same syntax (which resembles ggplot syntax).
same map with tmap:
library(tmap)
tmap_mode("view") # make map interactive
tm_shape(data_sf_summary) +
tm_polygons(col = "counts",
n = 5,
palette = "Greens",
title = "How many point were counted in each region")
static map with tmap:
library(tmap)
tmap_mode("plot") # make map static
tm_shape(data_sf_summary) +
tm_polygons(col = "counts",
n = 5,
palette = "Greens",
title = "How many point were counted in each region") +
tm_layout(legend.position = c("right","top"))
For multiple countries
First create new sample points that cover Europe:
random_long_lat <-
data.frame(
long = sample(runif(1000, min = -7.5, max = 19.99), replace = F),
lat = sample(runif(1000, min = 38.69, max = 60.75), replace = F)
)
all <- rbind(data2, data3, data4, data5)
Then make the sf objects and find the counts of points in every polygon:
all_sf <- all %>% st_as_sf()
random_long_lat_sf <- random_long_lat %>%
st_as_sf(coords = c("long", "lat"), crs = 4326)
all_sf_summary <- all_sf %>%
mutate(counts = lengths(st_intersects(., random_long_lat_sf)))
qtm(random_long_lat_sf)
Option 1: Choose maps from a list object by name using the NAME_0 column.
tmap_mode("view") # make maps interactive
list_of_maps <- map(unique(all_sf_summary$NAME_0),
~ tm_shape(all_sf_summary %>%
filter(NAME_0 == .x)) + # filter the data for your country of interest
tm_polygons(col = "counts",
n = 5,
palette = "Greens",
alpha = 0.85,
border.col = NA,
title = "How many point were counted in each region") +
tm_layout(legend.position = c("right","top"))) %>%
set_names(unique(all_sf_summary$NAME_0))
list_of_maps[['France']]
list_of_maps[['Portugal']]
Option 2: Show all the maps at once
### all maps at once
tm_shape(all_sf_summary) + # filter the data for your country of interest
tm_polygons(col = "counts",
n = 5,
palette = "Greens",
alpha = 0.85,
border.col = NA,
title = "How many point were counted in each region") +
tm_layout(legend.position = c("right","top")) +
tm_facets(by = c("NAME_0"), ncol = 2, showNA = FALSE)
So i'm trying to include some numeric figures in my label but am struggling to get it in the correct accounting format so that it is consistent with the legend. I have no trouble producing the labels without any numeric formatting, so any help in achieving the desired thousands separator would be brilliant.
library(geojson)
library(geojsonio)
library(leaflet)
library(sf)
url <- "http://leafletjs.com/examples/choropleth/us-states.js"
doc <- readLines(url)
doc2 <- gsub("var statesData = ", "", doc)
write(doc2, file = "tempgeo.json")
states <- geojson_read("tempgeo.json", what = "sp")
bins <- c(0, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, Inf)
pal <- colorBin("YlOrRd", domain = states$density, bins = bins)
states$density <- states$density*1000
c <- leaflet(states) %>%
setView(-96, 37.8, 4) %>%
addProviderTiles("MapBox", options = providerTileOptions(
id = "mapbox.light",
accessToken = Sys.getenv('MAPBOX_ACCESS_TOKEN')))
labels <- sprintf(
"<strong>%s</strong><br/>%g",
states$name, states$density
) %>% lapply(htmltools::HTML)
c <- c %>% addPolygons(
fillColor = ~pal(density),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7,
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
addLegend(pal = pal, values = ~density, opacity = 0.7, title = NULL,
position = "bottomright")
c
Thank you
You can convert the label to a string, and use prettyNum to format it with commas.
labels <- sprintf(
"<strong>%s</strong><br/>%s",
states$name, prettyNum(states$density, big.mark = ",")
) %>% lapply(htmltools::HTML)
I want to make a loop to add polygons to a leaflet map according to different columns of a data frame.
for (i in 18:22)
createMap = lapply((concello_wgs84_Datos#data[,i]),function(x){
data <- concello_wgs84_Datos#data[,i]
nombre <- names(concello_wgs84_Datos#data[,i])
pal3 <- leaflet::colorBin("YlOrRd", domain = data, 20, pretty = TRUE)
m = leaflet(data=concello_wgs84_Datos[1:17 & concello_wgs84_Datos#data[,i] == x], options = leafletOptions(minZoom = 8, maxZoom = 18)) %>%
addProviderTiles(providers$Esri.WorldImagery) %>% setView(-8.00, 42.80, zoom = 8.3) %>%
addPolygons(data=datos,
fill= TRUE,
fillColor = ~pal3(data),
stroke = FALSE,
color = "#0000CD",
smoothFactor = 0.5,
opacity = 1.0,
fillOpacity = 1,
weight = 0.5,
label = ~as.character(datos$CONCELLO),
labelOptions = labelOptions(noHide = F,
textsize = "7px",
direction = "topright"),
highlightOptions = highlightOptions(color = "white",
weight = 1,
bringToFront = TRUE)) %>%
addCircles(data = coordenadasOAC,
lat = ~ coordenadasOAC$LAT,
lng = ~ coordenadasOAC$LONG,radius =0.3,
color="#CD3333",
fillOpacity = 0.8,
popup = ~as.character(coordenadasOAC$OAC)) %>%
addLegend("bottomleft",
pal = pal3,
values = data,
title = nombre,
labFormat = labelFormat(prefix = ""),opacity = 1)})
htmltools::tagList(createMap)
but I have the following error: Error in`[.data.frameĀ“(x#data,i,j,...,drop=False): undefined columns selected.
Could you help me?
I have a dataset subsetted by month. However, when I graph each subset, the colorscale and range of legend are all different. How can I explicitly define this, so that it's consistent across all subsets?
So in the example below, I'd like the colorscale and range of legend to be the same for the unfiltered dataset and the filtered one.
github link to dataset
#original dataset. I want to construct the legend with this
weather <- read.csv("weather2_rmse.csv") %>%
mutate(date_of_forecast = as.Date(date_of_forecast))
#filtered. I want to construct the points with this
data <- filter(weather, date_of_forecast == "2015-02-01")
weather_map <- function(data) {
# change default color scale title
m <- list(colorbar = list(title = ""))
# geo styling
g <- list(
scope = 'north america',
showland = TRUE,
landcolor = toRGB("grey83"),
subunitcolor = toRGB("white"),
countrycolor = toRGB("white"),
showlakes = TRUE,
lakecolor = toRGB("white"),
showsubunits = TRUE,
showcountries = TRUE,
resolution = 50,
projection = list(
type = 'conic conformal',
rotation = list(lon = -100)
),
lonaxis = list(
showgrid = TRUE,
gridwidth = 0.5,
range = c(-140, -55),
dtick = 5
),
lataxis = list(
showgrid = TRUE,
gridwidth = 0.5,
range = c(20, 60),
dtick = 5
)
)
#the plotly part
p <- plot_geo(data, lat = ~latitude, lon = ~longitude, color = ~rmse) %>%
add_markers(
text = ~paste(data$rmse, "RMSE"), hoverinfo = "text"
) %>%
layout(title = 'Average RMSE of MaxTemp Forecasts by Month<br>xxxxxxxxxx', geo = g)
p
}
For example this way: Define a scale, e.g.
scl = list(c(0, "rgb(0, 0, 255)"), list(1, "rgb(0, 255, 0)"))
(You can also add more values, this is based on quantiles AFAIK. So setting it like this
scl = list(c(0, "rgb(0, 0, 255)"), list(0.1, "rgb(0, 0, 255)"),
c(0.1, "rgb(0, 255, 0)"), list(1, "rgb(0, 255, 0)"))
Will make the first 10% of your values be blue, the remainder green.
Then, modify your plot call e.g. like this:
p <- plot_geo(data) %>%
add_markers(y = ~latitude, x = ~longitude,
mode = "markers", type = "scatter",
marker = list(color = ~rmse,
colorscale = scl,
cauto = FALSE,
colorbar = list(title=""),
cmax = 15,
cmin = 0)) %>%
layout(title = 'Average RMSE of MaxTemp Forecasts by Month<br>xxxxxxxxxx', geo = g)
p
By setting the exact limits with cmax and cmin you should have the same scale across subplots
With this script, I am displaying a map with three isochrones. I would like the map to have labels containing the max time represented by each isochrone/polygon.
How should I reference the spatial data frames (iso1/2/3) in the addPolygons() section?
In each of the three addPolygons() bellow I tried a different approach but no luck :( (although the script still works).
library(osrm)
library(leaflet)
library(viridisLite)
# Making isochrones
iso1 = osrmIsochrone(loc = c(9.2,45.5),
breaks = seq(from = 0,
to = 45,
by = 5),
res=75)
iso2 = osrmIsochrone(loc = c(12.51182,41.92631),
breaks = seq(from = 0,
to = 45,
by = 15),
res=100)
iso3 = osrmIsochrone(loc = c(11.25581,43.76956),
breaks = seq(from = 0,
to = 45,
by = 15),
res=100)
# colors for leaflet
vir = viridis(9)
# palette
pal1 <- colorNumeric(
palette = vir,
domain = iso1#data$id)
pal2 <- colorNumeric(
palette = "Blues",
domain = iso2#data$id)
pal3 <- colorNumeric(
palette = "Reds",
domain = iso3#data$id)
# Plotting interactive map using spdf
leaflet()%>%
addTiles("http://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", attribution = 'Google')%>%
addPolygons(data = iso1,
fill = TRUE,
fillOpacity = 0.7,
fillColor = ~pal1(id),stroke = FALSE, label = iso1#data$max)%>%
addPolygons(data = iso2,
fill = TRUE,
fillOpacity = 0.7,
fillColor = ~pal2(id),stroke = FALSE, label = ~max)%>%
addPolygons(data = iso3,
fill = TRUE,
fillOpacity = 0.7,
fillColor = ~pal3(id),stroke = FALSE, label = ~iso3#data$max)
It works if you provide the max values as.character to the label.
library(osrm)
library(leaflet)
library(viridisLite)
# Making isochrones
iso1 = osrmIsochrone(loc = c(9.2,45.5),
breaks = seq(from = 0,
to = 45,
by = 5),
res=75)
iso2 = osrmIsochrone(loc = c(12.51182,41.92631),
breaks = seq(from = 0,
to = 45,
by = 15),
res=100)
iso3 = osrmIsochrone(loc = c(11.25581,43.76956),
breaks = seq(from = 0,
to = 45,
by = 15),
res=100)
# colors for leaflet
vir = viridis(9)
# palette
pal1 <- colorNumeric(
palette = vir,
domain = iso1#data$id)
pal2 <- colorNumeric(
palette = "Blues",
domain = iso2#data$id)
pal3 <- colorNumeric(
palette = "Reds",
domain = iso3#data$id)
# Plotting interactive map using spdf
leaflet()%>%
addTiles("http://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", attribution = 'Google')%>%
addPolygons(data = iso1,
fill = TRUE,
fillOpacity = 0.7,
fillColor = ~pal1(id),stroke = FALSE, label = as.character(iso1#data$max))%>%
addPolygons(data = iso2,
fill = TRUE,
fillOpacity = 0.7,
fillColor = ~pal2(id),stroke = FALSE, label = as.character(iso2#data$max))%>%
addPolygons(data = iso3,
fill = TRUE,
fillOpacity = 0.7,
fillColor = ~pal3(id),stroke = FALSE, label = as.character(iso3#data$max))
leaflet()%>%
addTiles("http://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", attribution = 'Google')%>%
addPolygons(data = iso1,
fill = TRUE,
group = "label1",
fillOpacity = 0.7,
fillColor = ~pal1(id),stroke = FALSE, label = iso1#data$max)%>%
addPolygons(data = iso2,
fill = TRUE,
group = "label2",
fillOpacity = 0.7,
fillColor = ~pal2(id),stroke = FALSE, label = ~max)%>%
addPolygons(data = iso3,
fill = TRUE,
group = "label3",
fillOpacity = 0.7,
fillColor = ~pal3(id),stroke = FALSE, label = ~iso3#data$max)
Use the group argument to specify the label.