0

How do you include a superscript in you leaflet legend title in R?

pal1 <- colorFactor("YlGn", domain = dataset$varaible, n = 3)

dataset %>% leaflet() %>%
  addProviderTiles("CartoDB.PositronNoLabels") %>%
  addPolygons(weight = 0.25, stroke = TRUE, color = "black", fillColor = ~pal1(dataset$variable), label = ~paste0("SCORE: ", variable)) %>%
  addLegend("bottomright", pal = pal1, values = ~variable, title = "ICE Race)

I would like the 'Race' to be a superscript. Thanks!

  • 4
    Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (please be explicit about non-base packages), sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. (This might be why your previous question did not get much response either?) – r2evans Aug 20 '23 at 21:43

1 Answers1

1

You could achieve your desired result by wrapping Race in a <sup> tag.

Using some fake example data based on mtcars:

library(leaflet)

dataset <- mtcars[, "cyl", drop = FALSE]
names(dataset) <- "variable"

pal1 <- colorFactor("YlGn", domain = dataset$variable, n = 3)

dataset %>% 
  leaflet() %>%
  addProviderTiles("CartoDB.PositronNoLabels") %>%
  addLegend("bottomright",
    pal = pal1,
    values = ~variable, title = "ICE<sup>Race</sup>"
  )

enter image description here

stefan
  • 90,330
  • 6
  • 25
  • 51