I've created a leaflet map and I'm trying to figure out how I can change the formatting of the legend labels. I currently have a gradient color palette to represent the data, with a set of discrete labels. Basically, the current output has the numbers aligned above the tick marks, and I would like them to be centered with the tick mark and justified left. See this image for reference.
pal <- colorNumeric(
palette = "YlOrRd",
domain = dat$distance)
m <- leaflet() %>%
addProviderTiles(providers$Esri.WorldGrayCanvas) %>%
addCircleMarkers(data = dat, #eastbound colored circles
radius = dat$total_ridership,
stroke = TRUE,
color = ~pal(distance), fillOpacity = 0.8)
ui <- fluidPage(
leafletOutput(outputId = "map")
)
server <- function(input,output){
output$map = renderLeaflet ({
m %>%
addLegend("bottomright", pal = pal, values = dat$distance, bins = c(0,200,400,600),
title = "Distance (ft) to <br> nearest bus stop",
opacity = .8)
})
}
shinyApp(ui=ui,server=server)
I'm quite new to both leaflet and shiny, and I'm going through tutorials to learn how to use shiny as well so I'm gaining a basic understanding of how shiny works, but I'm still confused on how to edit some of the more specific aspects of the leaflet output, especially with the legend. I've seen this post to make a custom legend based on circle sizes, as well as this on changing the format of time labels, but I'm not sure how to apply this information in my case to edit the legend label formatting -- e.g. changing the position of the text, alignment, etc.