R/observed_bias_order.R

Defines functions observed_bias_order

Documented in observed_bias_order

#' Order observed bias data frame for plotting
#'
#' @param d Observed bias data frame. Must have columns `dropped` and `type`
#' @param by Character. Variable in `d` to order by.
#'
#' @return Data frame in the correct order
#' @export
observed_bias_order <- function(d, by) {
  grps_ <- d[d$type == "group" & !grepl("Hypothetical", d$dropped), ]
  grps <- which(d$type == "group" & !grepl("Hypothetical", d$dropped))
  grps <- grps[order(grps_[[by]], decreasing = TRUE)]

  hypo_ <- d[d$type == "tip", ]
  hypo <- which(d$type == "tip")
  hypo <- hypo[order(hypo_[[by]])]

  d <- d[c(hypo, grps, order(d[[by]][d$type == "covariate"], decreasing = TRUE)), ]
  d$dropped <- factor(d$dropped,
                      levels = d$dropped)
  d
}

Try the tipr package in your browser

Any scripts or data that you put into this service are public.

tipr documentation built on Sept. 5, 2022, 5:09 p.m.