How to change mapview labels to currency format?

Hi! I used mapview to create a quick & easy map that shows changes in median home value for census tracts. However, I'm having a hard time changing the format of the numeric labels to display in a currency format/dollar value. I'm so used to just being able to use scales::label_dollar with ggplot, and I tried mapview(mv_shift, zcol = "mv_shift", label = label_dollar()) but I got the error "cannot coerce type 'closure' to vector of type 'character'" no matter how I tried it.

I can't find any clear answer in the documentation. In the mapview reference, the only help for "label" is "See addControl for details." There wasn't a link for addControl, but I'm pretty sure it refers to the leaflet function. This lead me to labelOptions, but if this is the correct formula to use I haven't been able to figure out how to incorporate it. There is a leaflet function, addLegend(labFormat = labelFormat()) that has the options I need (prefix, big.mark), but I think you can only use this function for a legend. I've tried incorporating countless leaflet label functions but all fail.

I'm about to either 1. add a new column where I try and format to the label output I want or 2. just use leaflet, but I was wondering if someone knew something I'm missing.

library(mapview)

# problem , how to format these labels ?
b2 <- breweries %>% filter(!is.na(number.seasonal.beers))
mapview(b2,label=as.character(b2$number.seasonal.beers))


# solution
ld <- scales::label_dollar()
mapview(b2,label=ld(b2$number.seasonal.beers))
1 Like

Yayyy, I'm so happy there was an easy solution. Thank you so much!

This topic was automatically closed 7 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.