简体   繁体   中英

How to limit legend width with an expression in the title in tmap?

I have encountered some unexpected behavior in the tmap library and was wondering if there is a way around it. When producing a map with an expression in the legend title, the legend becomes too wide for some reason.

Here's some code to show what I mean:

library(tmap)
data("World")

# Produces normal legend window
tm_shape(World) +
  tm_polygons("HPI") +
  tm_layout(legend.bg.color = "#AAAAAA")

# Produces wide legend window
title <- expression(Local~G[i]^"*")
tm_shape(World) +
  tm_polygons("HPI", title = title) +
  tm_layout(legend.bg.color = "#AAAAAA")

I tried using the legend.width parameter of tm_layout , but that messes up the font and symbol size down the line. Any ideas how to fix this? Thanks!

It seems like tmap just takes the unparsed length of your title as the legend.width and since your expression width is substantial due to sub/superscripts, you end up with a very wide frame. I couldn't find a way to prevent tmap from rescaling the text when legend.width is used. One solution would be to just remove the background color. Not ideal, but takes care of the weird width issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM