如何为 R 传单图图例添加下标和上标?

问题描述 投票:0回答:1

如何为 R 传单图例标题添加上标和下标。例如下面例子中的m2?

library(leaflet)
library(mapview) ## for the breweries dataset


## palette for the legend
palB <- colorNumeric('Blues', seq(1,14, by = 2))

##create a leaflet plot with legend
leaflet() %>% 
  addProviderTiles('CartoDB.Positron') %>%
  addCircleMarkers(data = breweries, color = ~palB(number.of.types)) %>% 
  addLegend(pal = palB, values = breweries$number.of.types, title = "size (m2)")

我已经尝试过了

expression "'size'*' ('m'^2*')'"

但它只是打印出来

r r-leaflet superscript
1个回答
2
投票

只需使用相应的 html 标签:

title = "size (m<sup>2</sup>)"

library(leaflet)
library(mapview) ## for the breweries dataset

## palette for the legend
palB <- colorNumeric('Blues', seq(1,14, by = 2))

##create a leaflet plot with legend
leaflet() %>% 
  addProviderTiles('CartoDB.Positron') %>%
  addCircleMarkers(data = breweries, color = ~palB(number.of.types)) %>% 
  addLegend(pal = palB, values = breweries$number.of.types, title = "size (m<sup>2</sup>)")

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.