R语言leaflegend包,addLeafLegends函数,图例样式

R语言,addLeafLegends函数,图例样式

addLeafLegends #图例样式 (4).png

addLeafLegends #图例样式 (1).png
addLeafLegends #图例样式 (2).png
addLeafLegends #图例样式 (3).png
# Tue Feb 02 00:54:02 2021 -

# 字符编码:UTF-8
# R 版本:R x64 4.0.3 for window 10
# [email protected]
# 个人笔记不负责任
# —— 拎了个梨
rm(list=ls());gc()
.rs.restartR()
require(leaflegend)
library(leaflet)
# install.packages('htmltools')

?addLeafLegends #图例样式

data(quakes);head(quakes)
# Tue Feb 02 01:17:51 2021 -----1-渐变图例------------------------

numPal <- colorNumeric('viridis', quakes$depth) #  颜色映射

leaflet() %>%
  # addTiles() %>%
  addLegendNumeric(
    pal = numPal, #从colorNumeric生成的调色板函数
    values = quakes$depth, #  从调色板函数生成颜色的值
    position = 'topright',
    title = '标题addLegendNumeric (Horizontal)',
    orientation = c("vertical","horizontal"), #  显示刻度
    shape = 'rect', #颜色符号的形状 !!!
    decreasing = F,  #  从小大或从大到小
    bins = 6, #  刻度分成几份
    height = 200, #  高度
    width = 100 #  宽度
    ,tickLength = 30, #  刻度线长
    tickWidth = 10 #  刻度线宽
  ) %>%
  addLegendNumeric(
    pal = numPal,
    values = quakes$depth,
    position = 'topright',
    title = htmltools::tags$div('标题2addLegendNumeric (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')

# Tue Feb 02 01:16:57 2021 -----2-分组图例------------------------

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')

# Tue Feb 02 01:14:47 2021 ---3-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')

# Tue Feb 02 01:15:52 2021 ----4.文本样式图例--------------------------

binPal <- colorBin('Set1', quakes$mag)
leaflet() %>%
  addTiles() %>%
  addCircleMarkers(
    data = quakes,
    lat = ~ lat,
    lng = ~ long,
    color = ~ binPal(mag),
    opacity = 1,
    fillOpacity = 1
  ) %>%
  addLegendBin(
    pal = binPal,
    values = quakes$mag,
    position = 'topright',
    title = 'addLegendBin',
    labelStyle = 'font-size: 18px; font-weight: bold;',
    orientation = 'horizontal'
  ) %>%
  addLegend(pal = binPal,
            values = quakes$mag,
            title = 'addLegend')
# Tue Feb 02 01:16:46 2021 --end


你可能感兴趣的:(R语言leaflegend包,addLeafLegends函数,图例样式)