这是indexloc提供的服务,不要输入任何密码
Skip to content

What are the units of width in tm_scalebar() #1168

@see24

Description

@see24

I got the following error message when I supplied 0.5 for the width in tm_scalebar. Eventually I figured out that it needed fairly large numbers but I still don't know what the units of width are. It is not described in the documentation. It would be great to have a more clear error message and details on the units in the docs.
Thanks!!

library(tmap)
tm_shape(World, bbox = World) +
  tm_text("name", size="pop_est", col="continent",
          col.scale = tm_scale_categorical(values = "seaborn.dark"),
          col.legend = tm_legend_hide(),
          size.scale = tm_scale_continuous(values.scale = 4),
          size.legend = tm_legend_hide())+
  tm_scalebar(width = 0.5)
#> [tip] Consider a suitable map projection, e.g. by adding `+ tm_crs("auto")`.
#> Scale bar set for latitude km and will be different at the top and bottom of the map.
#> 
#> This message is displayed once per session.
#> Error in tmapGridCompPlot.tm_scalebar(X[[i]], ...): object 'sbW' not found

tm_shape(World, bbox = World) +
  tm_text("name", size="pop_est", col="continent",
          col.scale = tm_scale_categorical(values = "seaborn.dark"),
          col.legend = tm_legend_hide(),
          size.scale = tm_scale_continuous(values.scale = 4),
          size.legend = tm_legend_hide())+
  tm_scalebar(width = 10)
#> Scale bar set for latitude km and will be different at the top and bottom of the map.

tm_shape(World, bbox = World) +
  tm_text("name", size="pop_est", col="continent",
          col.scale = tm_scale_categorical(values = "seaborn.dark"),
          col.legend = tm_legend_hide(),
          size.scale = tm_scale_continuous(values.scale = 4),
          size.legend = tm_legend_hide())+
  tm_scalebar(width = 100)
#> Scale bar set for latitude km and will be different at the top and bottom of the map.

Created on 2025-07-16 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions