简体   繁体   English

如何使用tmap标题中的表达式限制图例宽度?

[英]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. 我在tmap库中遇到了一些意外的行为,想知道是否有解决方法。 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. 我尝试使用legend.width的参数tm_layout ,但食堂的字体和符号大小的路线。 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. 看起来tmap只是将标题的未解析长度用作legend.width并且由于子/上标导致表达式的宽度很大,因此最终会得到非常宽的框架。 I couldn't find a way to prevent tmap from rescaling the text when legend.width is used. 我无法找到一个方法来防止tmap从重新缩放文本时legend.width使用。 One solution would be to just remove the background color. 一种解决方案是仅去除背景色。 Not ideal, but takes care of the weird width issue. 不理想,但要解决奇怪的宽度问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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