单行图例名称两行

时间:2018-11-05 01:11:15

标签: r leaflet legend

我试图将图例的名称放在两行中,但通常的方法不起作用。您能帮我找出原因吗?

library(leaflet)

    dfXL = data.frame(
    lat = as.numeric(c("-30","-30.1","-30.5")),
    lng = as.numeric(c("14","14.6","14.6")),
    sizeXL = as.numeric(c("1","2","3")),
    color = "red")
    #dfXL
    palXL <- colorNumeric(palette=c("#FFFFFF","#FFA07A"), as.numeric(as.character(dfXL$sizeXL)))

    dfXL$size_color<- palXL(dfXL$sizeXL)
    dfXL
    XL = leaflet(dfXL)%>% 
    setView(lng = 10.132974, lat = 10.706839, zoom = 3) %>% 
    addProviderTiles("Esri.WorldImagery") %>% 
    addCircleMarkers(radius = ~sizeXL/25 , color = ~size_color, fill = F,clusterOptions = markerClusterOptions(freezeAtZoom = 16),opacity=1) %>%
    addLegend("bottomright",labels=dfXL$sizeXL,title=paste(expression(atop("a","b"))),opacity=1,colors=dfXL$size_color)

    XL

1 个答案:

答案 0 :(得分:1)

使用</br>引入休息时间

复制并粘贴此可复制示例:

library(leaflet)
library(raster)
p <- shapefile(system.file("external/lux.shp", package="raster"))

pal <- colorNumeric(
  palette = "Reds",
  domain = p$AREA)

p %>% 
  leaflet() %>% 
  addTiles() %>% 
  addPolygons(stroke=FALSE, color = ~pal(AREA), fillOpacity = 1) %>% 
  addLegend(pal = pal, values = ~AREA, title = "line 1 </br> line 2")