Making "Labels" More Visible in R

I made the following map in R:

library(dplyr)
library(leaflet)

map_data <- data.frame("Lat" = c(43.6426, 43.6424, 43.6544, 43.6452, 43.6629), "Long" = c(-79.3871, -79.3860, -79.3807, -79.3806,-79.3957 ), type = c(1,2,3,4,5))
map_data$type = as.factor(map_data$type)


leaflet(map_data) %>% addTiles() %>% addCircleMarkers(stroke = FALSE, label = ~type,
    labelOptions = labelOptions(noHide = TRUE, offset=c(0,-12), fill = TRUE, opacity = 10, weight = 10, textOnly = TRUE))

But the problem is, you can barely see the "labels" for each city:

I would like to make the "labels" a lot more noticeable, something like this:

image

I tried to play around with the "weight" and "opacity" arguments, but this does not seem to be working.

Can someone please show me how to do this?

Thanks!

Note: I do not want to do this in R SHINY, just using LEAFLET in R.

Reference: https://stackoverflow.com/questions/43463150/print-label-on-circle-markers-in-leaflet-in-rshiny

use fillOpacity:

%>% addCircleMarkers(stroke = FALSE, label = ~type,
  fillOpacity = 0.9, 
  labelOptions =  [...]

G.

1 Like

Thank you for your answer! I tried your code:


library(dplyr)
library(leaflet)

map_data <- data.frame("Lat" = c(43.6426, 43.6424, 43.6544, 43.6452, 43.6629), "Long" = c(-79.3871, -79.3860, -79.3807, -79.3806,-79.3957 ), type = c(1,2,3,4,5))
map_data$type = as.factor(map_data$type)


leaflet(map_data) %>% addTiles() %>% addCircleMarkers(stroke = FALSE, label = ~type,
                                                      labelOptions = labelOptions(noHide = TRUE, offset=c(0,-12), fill = TRUE, Fillopacity = 20, weight = 10, textOnly = TRUE))

It still doesn't seem to be more noticeable?

Thank you so much!

It has to be before labelOptions = (....). Please have a look on help for ?addCircleMarkers -- fillOpacity is another argument like labelOptions and shouldn't be within labelOptions:

addCircleMarkers(
  map,
  lng = NULL,
  lat = NULL,
  radius = 10,
  layerId = NULL,
  group = NULL,
  stroke = TRUE,
  color = "#03F",
  weight = 5,
  opacity = 0.5,
  fill = TRUE,
  fillColor = color,
  fillOpacity = 0.2,
  dashArray = NULL,
  popup = NULL,
  popupOptions = NULL,
  label = NULL,
  labelOptions = NULL,
  options = pathOptions(),
  clusterOptions = NULL,
  clusterId = NULL,
  data = getMapData(map)
)
1 Like

Thank you for all your help!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.