Skip to content

notes on sense barchart #4

@mabafaba

Description

@mabafaba

user interface

I think it's not abstracted enough for a user facing function. maybe it should have a wrapper that does something like this:

barchart_orientation<-function(.data, plot.width){
...
return(sens_barchart(...))

}

readable code

few things can be made more readable, for example:

list_size_char_label <- nchar(levels(independent.var.value[[name_var]]))  ## to change

  list_logical_size <- lapply(list_size_char_label, function(x){if(x > size_max_label) return(TRUE) else return(FALSE)} ) ##nbre de caractere difini en fonction taille output

  if(nbre_bars > max_nbr_var || TRUE %in% list_logical_size ){
    #nbre doit dependre de la taille du output par exemple
    sens_barchart <- "horizontal"
  }
  else{
    sens_barchart <- "vertical"
  }

replace with


label_length<-nchar(unique(as.character(var)))
too_long_labels<- any(  label_length > size_max_label)
too_many_bars <- nbre_bars > max_nbr_var
horizontal <- too_long_labels | too_many_bars

orientation <- ifelse(horizontal,"horizontal" ,"vertical")

  • using unique(as.character()) instead of levels() to make sure it also works with non-factors:
  • nesting (including if, for, *apply) is always difficult to think about, because it creates all those levels of code you need to keep in mind. It's good to keep them as short as possible.
  • the point of making new objects ("<-") is to give them a name; so the new object should be a meaningful "thing" in your process. in this case: length of labels; are the labels too long? are there too many bars? can the barchart be horizontal?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions