boxuancui / DataExplorer

Compare 68f22f4 ... +0 ... 32552f6

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 1 of 139 files from the diff.
Other files ignored by Codecov
docs/404.html has changed.
docs/authors.html has changed.
man/plot_bar.Rd has changed.
docs/pkgdown.js has changed.
README.md has changed.
docs/index.html has changed.
docs/pkgdown.css has changed.
docs/pkgdown.yml has changed.
NEWS.md has changed.
docs/CONDUCT.html has changed.
cran-comments.md has changed.
README.Rmd has changed.
DESCRIPTION has changed.

@@ -3,6 +3,8 @@
Loading
3 3
#' Plot bar chart for each discrete feature, based on either frequency or another continuous feature.
4 4
#' @param data input data
5 5
#' @param with name of continuous feature to be summed. Default is \code{NULL}, i.e., frequency.
6 +
#' @param by discrete feature name to be broken down by.
7 +
#' @param by_position position argument in \link{geom_bar} if \code{by} is supplied. Default is \code{"fill"}.
6 8
#' @param maxcat maximum categories allowed for each feature. Default is 50.
7 9
#' @param order_bar logical, indicating if bars should be ordered. Default is \code{TRUE}.
8 10
#' @param binary_as_factor treat binary as categorical? Default is \code{TRUE}.
@@ -26,10 +28,15 @@
Loading
26 28
#' plot_bar(diamonds)
27 29
#' plot_bar(diamonds, maxcat = 5)
28 30
#'
29 -
#' # Plot bar charts with `price` feature
31 +
#' # Plot bar charts with `price`
30 32
#' plot_bar(diamonds, with = "price")
33 +
#' 
34 +
#' # Plot bar charts by `cut`
35 +
#' plot_bar(diamonds, by = "cut")
36 +
#' plot_bar(diamonds, by = "cut", by_position = "dodge")
31 37
32 38
plot_bar <- function(data, with = NULL,
39 +
                     by = NULL, by_position = "fill",
33 40
                     maxcat = 50, order_bar = TRUE, binary_as_factor = TRUE,
34 41
                     title = NULL,
35 42
                     ggtheme = theme_gray(), theme_config = list(),
@@ -68,8 +75,14 @@
Loading
68 75
    tmp_dt <- data.table(discrete, "measure" = measure_var)
69 76
    dt <- tmp_dt[, list(frequency = sum(measure, na.rm = TRUE)), by = feature_names]
70 77
  }
71 -
  dt_tmp <- suppressWarnings(melt.data.table(dt, measure.vars = feature_names))
72 -
  dt2 <- dt_tmp[, list(frequency = sum(frequency)), by = list(variable, value)]
78 +
  if (is.null(by)) {
79 +
    dt_tmp <- suppressWarnings(melt.data.table(dt, measure.vars = feature_names))
80 +
    dt2 <- dt_tmp[, list(frequency = sum(frequency)), by = list(variable, value)]
81 +
  } else {
82 +
    if (!(by %in% feature_names)) stop(paste0(by, " is not found as a discrete feature!"))
83 +
    dt_tmp <- suppressWarnings(melt.data.table(dt, measure.vars = setdiff(feature_names, by)))
84 +
    dt2 <- dt_tmp[, list(frequency = sum(frequency)), by = c("variable", "value", by)]
85 +
  }
73 86
  dt2[, facet_value := paste0(value, "___", variable)]
74 87
  ## Calculate number of pages
75 88
  layout <- .getPageLayout(nrow, ncol, ncol(discrete))
@@ -79,15 +92,24 @@
Loading
79 92
    X = layout,
80 93
    FUN = function(x) {
81 94
      if (order_bar) {
82 -
        base_plot <- ggplot(dt2[variable %in% feature_names[x]], aes(x = reorder(facet_value, frequency), y = frequency))
95 +
        base_plot <- ggplot(dt2[variable %in% feature_names[x]],
96 +
                            aes(x = reorder(facet_value, frequency), y = frequency))
83 97
      } else {
84 98
        base_plot <- ggplot(dt2[variable %in% feature_names[x]], aes(x = value, y = frequency))
85 99
      }
86 -
      base_plot +
87 -
        geom_bar(stat = "identity") +
100 +
      if (is.null(by)) {
101 +
        base_plot2 <- base_plot +
102 +
          geom_bar(stat = "identity") +
103 +
          ylab(ifelse(is.null(with), "Frequency", toTitleCase(with)))
104 +
      } else {
105 +
        base_plot2 <- base_plot +
106 +
          geom_bar(stat = "identity", aes_string(fill = by), position = by_position) +
107 +
          ylab("")
108 +
      }
109 +
      base_plot2 +
88 110
        scale_x_discrete(labels = function(x) tstrsplit(x, "___")[[1]]) +
89 111
        coord_flip() +
90 -
        xlab("") + ylab(ifelse(is.null(with), "Frequency", toTitleCase(with)))
112 +
        xlab("")
91 113
    }
92 114
  )
93 115
  ## Plot objects

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
R 0.10% 94.14%
Project Totals (23 files) 94.14%
Loading