Skip to content

Feature request: Add background parameter for sbar() when type = "bar" #1957

@lsalinasm23

Description

@lsalinasm23

Currently, the sbar() function in terra allows adding a white background (“halo”) only when type = "line" via the argument halo = TRUE.
However, when type = "bar", there is no way to add a background color behind the scale bar. This becomes an issue when the scale bar is drawn over complex basemaps (e.g., satellite or topographic images), where the divisions and labels become difficult to read.

It would be useful to include an argument such as:

bty = "o"          # draw box around the scale bar
box.col = "black"  # box border color
bg = "white"       # box background color (with support for transparency)

This would make it possible to create a readable and visually consistent scale bar, for example:

# Example: semitransparent white background for readability
sbar(15, 
c(6.3, 50),
type="bar",
below="km",
label=c(0,7.5,15), cex=.8,
bty = "o",
box.col = "black",
bg = rgb(1, 1, 1, alpha = 0.7)
)

This would improve the visibility of the scale bar on maps with dark or detailed backgrounds, and maintain consistency with how other base plotting functions (like legend()) handle background color.

Furthermore, implementing the same argument for the "line" type could replace and simplify the current halo parameter, providing a unified and more flexible way to control background color for both types of scale bars.

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