Skip to content

format vector values with decimal.mark and big.mark #6

@NChauvot

Description

@NChauvot

Bonjour,

Je voudrai proposer d'ajouter la possibilité d'utiliser le séparateur décimal et un espace entre les milliers,
pour les légendes 'prop' 'prop_line' et 'cont'.

L'inconvénient c'est qu'une fois formaté avec un séparateur décimal et un séparateur entre les milliers, le vecteur ne peut alors plus être converti en numérique, or ce vecteur est utilisé en numérique dans les fonctions 'prop' 'prop_line' et 'cont'.

Je suggère d'ajouter un ellipse '...' dans la fonction auxiliaire get_val_rnd et une utilisation du vecteur de valeurs formatées avec un séparateur décimal et un séparateur entre les milliers au moment de l'affichage dans la fonction text.

Merci d'envisager cette amélioration dans une version ultérieure.

Formated vector of values with decimal.mark and big.mark can be plot by text function but it can't be used as numeric values._
So it's not possible to use it in lg_prop, lg_cont, and lg_prop_line legend.
Thanks for considering adding a decimal.mark and big.mark in lg_prop(), lg_cont(), lg_prop_line() and leg() function._

suggest in lg_utils :

## get_val_rnd  modified 
#' Title
#'
#' @param val val
#' @param val val_rnd
#' @noRd
get_val_rnd <- function(val, val_rnd, ...) {
  if (is.numeric(val)) {
    val <- round(val, val_rnd)
    if (val_rnd <= 0) {
      val_rnd <- 0
    }
    val <- format(x = val, scientific = FALSE, nsmall = val_rnd, ...)
    val <- trimws(val)
  }
  val
}

suggest in lg_prop :

[...]

#' @param val_rnd number of decimal places of the values in the legend.
#' @param val_decimal_mark format the values decimal mark in the legend.
#' @param val_big_mark format the values beetween thousand in the legend.

[...]

leg_prop <- function(
# [...]
val_rnd = 0,
val_decimal_mark='.',
val_big_mark='',
# [...]
)

[...]

valleg <- get_val_rnd(val = val, val_rnd = val_rnd)
valleg2 <- get_val_rnd(val = val,val_rnd = val_rnd,big.mark=val_big_mark,decimal.mark=val_decimal_mark)

[...]

text(
xy_lab$x,
y = xy_lab$y,
labels = rev(valleg2),
cex = val_cex,
adj = c(0, 0.5),
col = fg
)

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