diff --git a/.lintr b/.lintr new file mode 100644 index 0000000..93e4806 --- /dev/null +++ b/.lintr @@ -0,0 +1,11 @@ +linters: linters_with_defaults( + line_length_linter(80), + single_quotes_linter = NULL, + object_name_linter = object_name_linter("camelCase"), + spaces_inside_linter = NULL + ) +exclusions: list( + "inst/", + "tests/" + ) +encoding: "UTF-8" diff --git a/R/legend.R b/R/legend.R index 07b6e42..b360020 100644 --- a/R/legend.R +++ b/R/legend.R @@ -1082,6 +1082,7 @@ addLegendQuantile <- function(map, #' addLegendBin <- function(map, pal, + values, title = NULL, labelStyle = '', shape = c('rect', 'circle', 'triangle', 'plus', diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 8ab2390..ead4c7f 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -2,7 +2,7 @@ pandoc: '2.18' pkgdown: 2.0.4 pkgdown_sha: ~ articles: {} -last_built: 2022-08-01T15:37Z +last_built: 2022-08-03T22:07Z urls: reference: https://leaflegend.roh.engineering/reference article: https://leaflegend.roh.engineering/articles diff --git a/docs/reference/addLeafLegends.html b/docs/reference/addLeafLegends.html index fb0dbf4..b4051c3 100644 --- a/docs/reference/addLeafLegends.html +++ b/docs/reference/addLeafLegends.html @@ -18,7 +18,7 @@ gtag('js', new Date()); gtag('config', 'G-FEY7F5BR1Z'); -
+ Skip to contents @@ -122,6 +122,7 @@library(leaflet)
-
-data(quakes)
-
-# Numeric Legend
-
-numPal <- colorNumeric('viridis', quakes$depth)
-leaflet() %>%
- addTiles() %>%
- addLegendNumeric(
- pal = numPal,
- values = quakes$depth,
- position = 'topright',
- title = 'addLegendNumeric (Horizontal)',
- orientation = 'horizontal',
- shape = 'rect',
- decreasing = FALSE,
- height = 20,
- width = 100
- ) %>%
- addLegendNumeric(
- pal = numPal,
- values = quakes$depth,
- position = 'topright',
- title = htmltools::tags$div('addLegendNumeric (Decreasing)',
- style = 'font-size: 24px; text-align: center; margin-bottom: 5px;'),
- orientation = 'vertical',
- shape = 'stadium',
- decreasing = TRUE,
- height = 100,
- width = 20
- ) %>%
- addLegend(pal = numPal, values = quakes$depth, title = 'addLegend')
-
-
-# Quantile Legend
-# defaults to adding quantile numeric break points
-
-quantPal <- colorQuantile('viridis', quakes$mag, n = 5)
-leaflet() %>%
- addTiles() %>%
- addCircleMarkers(data = quakes,
- lat = ~lat,
- lng = ~long,
- color = ~quantPal(mag),
- opacity = 1,
- fillOpacity = 1
- ) %>%
- addLegendQuantile(pal = quantPal,
- values = quakes$mag,
- position = 'topright',
- title = 'addLegendQuantile',
- numberFormat = function(x) {prettyNum(x, big.mark = ',',
- scientific = FALSE, digits = 2)},
- shape = 'circle') %>%
- addLegendQuantile(pal = quantPal,
- values = quakes$mag,
- position = 'topright',
- title = htmltools::tags$div('addLegendQuantile',
- htmltools::tags$br(),
- '(Omit Numbers)'),
- numberFormat = NULL,
- shape = 'circle') %>%
- addLegend(pal = quantPal, values = quakes$mag, title = 'addLegend')
-
-
-# Factor Legend
-# Style the title with html tags, several shapes are supported drawn with svg
-
-quakes[['group']] <- sample(c('A', 'B', 'C'), nrow(quakes), replace = TRUE)
-factorPal <- colorFactor('Dark2', quakes$group)
-leaflet() %>%
- addTiles() %>%
- addCircleMarkers(
- data = quakes,
- lat = ~ lat,
- lng = ~ long,
- color = ~ factorPal(group),
- opacity = 1,
- fillOpacity = 1
- ) %>%
- addLegendFactor(
- pal = factorPal,
- title = htmltools::tags$div('addLegendFactor', style = 'font-size: 24px;
- color: red;'),
- values = quakes$group,
- position = 'topright',
- shape = 'triangle',
- width = 50,
- height = 50
- ) %>%
- addLegend(pal = factorPal,
- values = quakes$group,
- title = 'addLegend')
-
-
-# Bin Legend
-# Restyle the text of the labels, change the legend item orientation
-
-binPal <- colorBin('Set1', quakes$mag)
-leaflet() %>%
- addTiles() %>%
- addCircleMarkers(
- data = quakes,
- lat = ~ lat,
- lng = ~ long,
- color = ~ binPal(mag),
- opacity = 1,
- fillOpacity = 1
- ) %>%
- addLegendBin(
- pal = binPal,
- position = 'topright',
- title = 'addLegendBin',
- labelStyle = 'font-size: 18px; font-weight: bold;',
- orientation = 'horizontal'
- ) %>%
- addLegend(pal = binPal,
- values = quakes$mag,
- title = 'addLegend')
-
-
-# Group Layer Control
-# Works with baseGroups and overlayGroups
-
-leaflet() %>%
- addTiles() %>%
- addLegendNumeric(
- pal = numPal,
- values = quakes$depth,
- position = 'topright',
- title = 'addLegendNumeric',
- group = 'Numeric Data'
- ) %>%
- addLegendQuantile(
- pal = quantPal,
- values = quakes$mag,
- position = 'topright',
- title = 'addLegendQuantile',
- group = 'Quantile'
- ) %>%
- addLegendBin(
- pal = binPal,
- position = 'bottomleft',
- title = 'addLegendBin',
- group = 'Bin'
- ) %>%
- addLayersControl(
- baseGroups = c('Numeric Data', 'Quantile'), overlayGroups = c('Bin'),
- position = 'bottomright'
- )
-
-
library(leaflet)
+
+data(quakes)
+
+# Numeric Legend
+
+numPal <- colorNumeric('viridis', quakes$depth)
+leaflet() %>%
+ addTiles() %>%
+ addLegendNumeric(
+ pal = numPal,
+ values = quakes$depth,
+ position = 'topright',
+ title = 'addLegendNumeric (Horizontal)',
+ orientation = 'horizontal',
+ shape = 'rect',
+ decreasing = FALSE,
+ height = 20,
+ width = 100
+ ) %>%
+ addLegendNumeric(
+ pal = numPal,
+ values = quakes$depth,
+ position = 'topright',
+ title = htmltools::tags$div('addLegendNumeric (Decreasing)',
+ style = 'font-size: 24px; text-align: center; margin-bottom: 5px;'),
+ orientation = 'vertical',
+ shape = 'stadium',
+ decreasing = TRUE,
+ height = 100,
+ width = 20
+ ) %>%
+ addLegend(pal = numPal, values = quakes$depth, title = 'addLegend')
+
+# Quantile Legend
+# defaults to adding quantile numeric break points
+
+quantPal <- colorQuantile('viridis', quakes$mag, n = 5)
+leaflet() %>%
+ addTiles() %>%
+ addCircleMarkers(data = quakes,
+ lat = ~lat,
+ lng = ~long,
+ color = ~quantPal(mag),
+ opacity = 1,
+ fillOpacity = 1
+ ) %>%
+ addLegendQuantile(pal = quantPal,
+ values = quakes$mag,
+ position = 'topright',
+ title = 'addLegendQuantile',
+ numberFormat = function(x) {prettyNum(x, big.mark = ',',
+ scientific = FALSE, digits = 2)},
+ shape = 'circle') %>%
+ addLegendQuantile(pal = quantPal,
+ values = quakes$mag,
+ position = 'topright',
+ title = htmltools::tags$div('addLegendQuantile',
+ htmltools::tags$br(),
+ '(Omit Numbers)'),
+ numberFormat = NULL,
+ shape = 'circle') %>%
+ addLegend(pal = quantPal, values = quakes$mag, title = 'addLegend')
+
+# Factor Legend
+# Style the title with html tags, several shapes are supported drawn with svg
+
+quakes[['group']] <- sample(c('A', 'B', 'C'), nrow(quakes), replace = TRUE)
+factorPal <- colorFactor('Dark2', quakes$group)
+leaflet() %>%
+ addTiles() %>%
+ addCircleMarkers(
+ data = quakes,
+ lat = ~ lat,
+ lng = ~ long,
+ color = ~ factorPal(group),
+ opacity = 1,
+ fillOpacity = 1
+ ) %>%
+ addLegendFactor(
+ pal = factorPal,
+ title = htmltools::tags$div('addLegendFactor', style = 'font-size: 24px;
+ color: red;'),
+ values = quakes$group,
+ position = 'topright',
+ shape = 'triangle',
+ width = 50,
+ height = 50
+ ) %>%
+ addLegend(pal = factorPal,
+ values = quakes$group,
+ title = 'addLegend')
+
+# Bin Legend
+# Restyle the text of the labels, change the legend item orientation
+
+binPal <- colorBin('Set1', quakes$mag)
+leaflet() %>%
+ addTiles() %>%
+ addCircleMarkers(
+ data = quakes,
+ lat = ~ lat,
+ lng = ~ long,
+ color = ~ binPal(mag),
+ opacity = 1,
+ fillOpacity = 1
+ ) %>%
+ addLegendBin(
+ pal = binPal,
+ position = 'topright',
+ title = 'addLegendBin',
+ labelStyle = 'font-size: 18px; font-weight: bold;',
+ orientation = 'horizontal'
+ ) %>%
+ addLegend(pal = binPal,
+ values = quakes$mag,
+ title = 'addLegend')
+
+# Group Layer Control
+# Works with baseGroups and overlayGroups
+
+leaflet() %>%
+ addTiles() %>%
+ addLegendNumeric(
+ pal = numPal,
+ values = quakes$depth,
+ position = 'topright',
+ title = 'addLegendNumeric',
+ group = 'Numeric Data'
+ ) %>%
+ addLegendQuantile(
+ pal = quantPal,
+ values = quakes$mag,
+ position = 'topright',
+ title = 'addLegendQuantile',
+ group = 'Quantile'
+ ) %>%
+ addLegendBin(
+ pal = binPal,
+ position = 'bottomleft',
+ title = 'addLegendBin',
+ group = 'Bin'
+ ) %>%
+ addLayersControl(
+ baseGroups = c('Numeric Data', 'Quantile'), overlayGroups = c('Bin'),
+ position = 'bottomright'
+ )
+
library(leaflet)
-data(quakes)
-iconSet <- awesomeIconList(
- `Font Awesome` = makeAwesomeIcon(icon = "font-awesome", library = "fa",
- iconColor = 'gold', markerColor = 'red',
- spin = FALSE,
- squareMarker = TRUE,
- iconRotate = 30,
- ),
- Ionic = makeAwesomeIcon(icon = "ionic", library = "ion",
- iconColor = '#ffffff', markerColor = 'blue',
- spin = TRUE,
- squareMarker = FALSE),
- Glyphicon = makeAwesomeIcon(icon = "plus-sign", library = "glyphicon",
- iconColor = 'rgb(192, 255, 0)',
- markerColor = 'darkpurple',
- spin = TRUE,
- squareMarker = FALSE)
-)
-leaflet(quakes[1:3,]) %>%
- addTiles() %>%
- addAwesomeMarkers(lat = ~lat,
- lng = ~long,
- icon = iconSet) %>%
- addLegendAwesomeIcon(iconSet = iconSet,
- orientation = 'horizontal',
- title = htmltools::tags$div(
- style = 'font-size: 20px;',
- 'Awesome Icons'),
- labelStyle = 'font-size: 16px;') %>%
- addLegendAwesomeIcon(iconSet = iconSet,
- orientation = 'vertical',
- marker = FALSE,
- title = htmltools::tags$div(
- style = 'font-size: 20px;',
- 'Awesome Icons'),
- labelStyle = 'font-size: 16px;')
-
-
library(leaflet)
+data(quakes)
+iconSet <- awesomeIconList(
+ `Font Awesome` = makeAwesomeIcon(icon = "font-awesome", library = "fa",
+ iconColor = 'gold', markerColor = 'red',
+ spin = FALSE,
+ squareMarker = TRUE,
+ iconRotate = 30,
+ ),
+ Ionic = makeAwesomeIcon(icon = "ionic", library = "ion",
+ iconColor = '#ffffff', markerColor = 'blue',
+ spin = TRUE,
+ squareMarker = FALSE),
+ Glyphicon = makeAwesomeIcon(icon = "plus-sign", library = "glyphicon",
+ iconColor = 'rgb(192, 255, 0)',
+ markerColor = 'darkpurple',
+ spin = TRUE,
+ squareMarker = FALSE)
+)
+leaflet(quakes[1:3,]) %>%
+ addTiles() %>%
+ addAwesomeMarkers(lat = ~lat,
+ lng = ~long,
+ icon = iconSet) %>%
+ addLegendAwesomeIcon(iconSet = iconSet,
+ orientation = 'horizontal',
+ title = htmltools::tags$div(
+ style = 'font-size: 20px;',
+ 'Awesome Icons'),
+ labelStyle = 'font-size: 16px;') %>%
+ addLegendAwesomeIcon(iconSet = iconSet,
+ orientation = 'vertical',
+ marker = FALSE,
+ title = htmltools::tags$div(
+ style = 'font-size: 20px;',
+ 'Awesome Icons'),
+ labelStyle = 'font-size: 16px;')
+
-library(leaflet)
-data(quakes)
-
-quakes1 <- quakes[1:10,]
-
-colors <- c('blue', 'red', 'yellow', 'green', 'orange', 'purple')
-i <- as.integer(cut(quakes$mag, breaks = quantile(quakes$mag, seq(0,1,1/6)),
- include.lowest = TRUE))
-leafImg <- system.file(sprintf('img/leaf-%s.png', colors),
- package = 'leaflegend')
-leafIcons <- icons(
- iconUrl = leafImg[i],
- iconWidth = 133/236 * 50, iconHeight = 50
-)
-leaflet(data = quakes) %>% addTiles() %>%
- addMarkers(~long, ~lat, icon = leafIcons) %>%
- addLegendImage(images = leafImg,
- labels = colors,
- width = 133/236 * 50,
- height = 50,
- orientation = 'vertical',
- title = htmltools::tags$div('Leaf',
- style = 'font-size: 24px;
- text-align: center;'),
- position = 'topright')
-
-
- # use raster images with size encodings
- height <- sizeNumeric(quakes$depth, baseSize = 40)
- width <- height * 38 / 95
- symbols <- icons(
- iconUrl = leafImg[4],
- iconWidth = width,
- iconHeight = height)
- probs <- c(.2, .4, .6, .8)
- leaflet(quakes) %>%
- addTiles() %>%
- addMarkers(icon = symbols,
- lat = ~lat, lng = ~long) %>%
- addLegendImage(
- images = rep(leafImg[4], 4),
- labels = round(quantile(height, probs = probs), 0),
- width = quantile(height, probs = probs) * 38 / 95,
- height = quantile(height, probs = probs),
- title = htmltools::tags$div(
- 'Leaf',
- style = 'font-size: 24px; text-align: center; margin-bottom: 5px;'),
- position = 'topright', orientation = 'vertical')
-
-
+library(leaflet)
+data(quakes)
+
+quakes1 <- quakes[1:10,]
+
+colors <- c('blue', 'red', 'yellow', 'green', 'orange', 'purple')
+i <- as.integer(cut(quakes$mag, breaks = quantile(quakes$mag, seq(0,1,1/6)),
+ include.lowest = TRUE))
+leafImg <- system.file(sprintf('img/leaf-%s.png', colors),
+ package = 'leaflegend')
+leafIcons <- icons(
+ iconUrl = leafImg[i],
+ iconWidth = 133/236 * 50, iconHeight = 50
+)
+leaflet(data = quakes) %>% addTiles() %>%
+ addMarkers(~long, ~lat, icon = leafIcons) %>%
+ addLegendImage(images = leafImg,
+ labels = colors,
+ width = 133/236 * 50,
+ height = 50,
+ orientation = 'vertical',
+ title = htmltools::tags$div('Leaf',
+ style = 'font-size: 24px;
+ text-align: center;'),
+ position = 'topright')
+
+ # use raster images with size encodings
+ height <- sizeNumeric(quakes$depth, baseSize = 40)
+ width <- height * 38 / 95
+ symbols <- icons(
+ iconUrl = leafImg[4],
+ iconWidth = width,
+ iconHeight = height)
+ probs <- c(.2, .4, .6, .8)
+ leaflet(quakes) %>%
+ addTiles() %>%
+ addMarkers(icon = symbols,
+ lat = ~lat, lng = ~long) %>%
+ addLegendImage(
+ images = rep(leafImg[4], 4),
+ labels = round(quantile(height, probs = probs), 0),
+ width = quantile(height, probs = probs) * 38 / 95,
+ height = quantile(height, probs = probs),
+ title = htmltools::tags$div(
+ 'Leaf',
+ style = 'font-size: 24px; text-align: center; margin-bottom: 5px;'),
+ position = 'topright', orientation = 'vertical')
+
library(leaflet)
-data("quakes")
-quakes <- quakes[1:100,]
-numPal <- colorNumeric('viridis', quakes$depth)
-sizes <- sizeNumeric(quakes$depth, baseSize = 10)
-symbols <- Map(
- makeSymbol,
- shape = 'triangle',
- color = numPal(quakes$depth),
- width = sizes,
- height = sizes
-)
-leaflet() %>%
- addTiles() %>%
- addMarkers(data = quakes,
- icon = icons(iconUrl = symbols),
- lat = ~lat, lng = ~long) %>%
- addLegendSize(
- values = quakes$depth,
- pal = numPal,
- title = 'Depth',
- labelStyle = 'margin: auto;',
- shape = c('triangle'),
- orientation = c('vertical', 'horizontal'),
- opacity = .7,
- breaks = 5)
-
-
-# a wrapper for making icons is provided
-sizeSymbols <-
-makeSymbolsSize(
- quakes$depth,
- shape = 'cross',
- fillColor = numPal(quakes$depth),
- color = 'black',
- strokeWidth = 1,
- opacity = .8,
- fillOpacity = .5,
- baseSize = 20
-)
-leaflet() %>%
- addTiles() %>%
- addMarkers(data = quakes,
- icon = sizeSymbols,
- lat = ~lat, lng = ~long) %>%
- addLegendSize(
- values = quakes$depth,
- pal = numPal,
- title = 'Depth',
- shape = 'cross',
- orientation = 'horizontal',
- strokeWidth = 1,
- opacity = .8,
- fillOpacity = .5,
- color = 'black',
- baseSize = 20,
- breaks = 5)
-
-
-# Group layers control
-leaflet() %>%
- addTiles() %>%
- addLegendSize(
- values = quakes$depth,
- pal = numPal,
- title = 'Depth',
- labelStyle = 'margin: auto;',
- shape = c('triangle'),
- orientation = c('vertical', 'horizontal'),
- opacity = .7,
- breaks = 5,
- group = 'Depth') %>%
- addLayersControl(overlayGroups = c('Depth'))
-
-
-# Polyline Legend for Size
-baseSize <- 10
-lineColor <- '#00000080'
-pal <- colorNumeric('Reds', atlStorms2005$MinPress)
-#> Loading required package: sp
-leaflet() %>%
- addTiles() %>%
- addPolylines(data = atlStorms2005,
- weight = ~sizeNumeric(values = MaxWind, baseSize = baseSize),
- color = ~pal(MinPress),
- popup = ~as.character(MaxWind)) %>%
- addLegendLine(values = atlStorms2005$MaxWind,
- title = 'MaxWind',
- baseSize = baseSize,
- width = 50,
- color = lineColor) %>%
- addLegendNumeric(pal = pal,
- title = 'MinPress',
- values = atlStorms2005$MinPress)
-
-
library(leaflet)
+data("quakes")
+quakes <- quakes[1:100,]
+numPal <- colorNumeric('viridis', quakes$depth)
+sizes <- sizeNumeric(quakes$depth, baseSize = 10)
+symbols <- Map(
+ makeSymbol,
+ shape = 'triangle',
+ color = numPal(quakes$depth),
+ width = sizes,
+ height = sizes
+)
+leaflet() %>%
+ addTiles() %>%
+ addMarkers(data = quakes,
+ icon = icons(iconUrl = symbols),
+ lat = ~lat, lng = ~long) %>%
+ addLegendSize(
+ values = quakes$depth,
+ pal = numPal,
+ title = 'Depth',
+ labelStyle = 'margin: auto;',
+ shape = c('triangle'),
+ orientation = c('vertical', 'horizontal'),
+ opacity = .7,
+ breaks = 5)
+
+# a wrapper for making icons is provided
+sizeSymbols <-
+makeSymbolsSize(
+ quakes$depth,
+ shape = 'cross',
+ fillColor = numPal(quakes$depth),
+ color = 'black',
+ strokeWidth = 1,
+ opacity = .8,
+ fillOpacity = .5,
+ baseSize = 20
+)
+leaflet() %>%
+ addTiles() %>%
+ addMarkers(data = quakes,
+ icon = sizeSymbols,
+ lat = ~lat, lng = ~long) %>%
+ addLegendSize(
+ values = quakes$depth,
+ pal = numPal,
+ title = 'Depth',
+ shape = 'cross',
+ orientation = 'horizontal',
+ strokeWidth = 1,
+ opacity = .8,
+ fillOpacity = .5,
+ color = 'black',
+ baseSize = 20,
+ breaks = 5)
+
+# Group layers control
+leaflet() %>%
+ addTiles() %>%
+ addLegendSize(
+ values = quakes$depth,
+ pal = numPal,
+ title = 'Depth',
+ labelStyle = 'margin: auto;',
+ shape = c('triangle'),
+ orientation = c('vertical', 'horizontal'),
+ opacity = .7,
+ breaks = 5,
+ group = 'Depth') %>%
+ addLayersControl(overlayGroups = c('Depth'))
+
+# Polyline Legend for Size
+baseSize <- 10
+lineColor <- '#00000080'
+pal <- colorNumeric('Reds', atlStorms2005$MinPress)
+leaflet() %>%
+ addTiles() %>%
+ addPolylines(data = atlStorms2005,
+ weight = ~sizeNumeric(values = MaxWind, baseSize = baseSize),
+ color = ~pal(MinPress),
+ popup = ~as.character(MaxWind)) %>%
+ addLegendLine(values = atlStorms2005$MaxWind,
+ title = 'MaxWind',
+ baseSize = baseSize,
+ width = 50,
+ color = lineColor) %>%
+ addLegendNumeric(pal = pal,
+ title = 'MinPress',
+ values = atlStorms2005$MinPress)
+