Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Aug 25, 2023
1 parent 7d8d194 commit c05e347
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
18 changes: 12 additions & 6 deletions R/plot.dw_data_tabulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#' @param na_label The label given to missing values (only when
#' `remove_na = FALSE`).
#' @param error_bar Boolean. Should error bars be displayed?
#' @param ... Unused
#'
#' @rdname plot.dw_data_tabulate
#' @export

plot.dw_data_tabulates <- function(x, value_lab = TRUE, remove_na = FALSE,
na_label = "(Missing)", error_bar = TRUE) {
na_label = "(Missing)", error_bar = TRUE,
...) {
lapply(x, plot.dw_data_tabulate,
value_lab = value_lab, remove_na = remove_na,
na_label = na_label, error_bar = error_bar
Expand All @@ -24,7 +26,8 @@ plot.dw_data_tabulates <- function(x, value_lab = TRUE, remove_na = FALSE,
#' @export

plot.dw_data_tabulate <- function(x, value_lab = TRUE, remove_na = FALSE,
na_label = "(Missing)", error_bar = TRUE) {
na_label = "(Missing)", error_bar = TRUE,
...) {
dat <- as.data.frame(x)

if (isTRUE(remove_na)) {
Expand Down Expand Up @@ -56,27 +59,30 @@ plot.dw_data_tabulate <- function(x, value_lab = TRUE, remove_na = FALSE,
dat$label <- paste0(dat$N, "\n(", round(dat$output, 2), "%)")
}

out <- ggplot(dat, aes(x = Value, y = N)) +
out <- ggplot(dat, aes(x = .data$Value, y = .data$N)) +
geom_col() +
labs(title = unique(dat$Variable)) +
theme_modern()

if (isTRUE(value_lab)) {
if (isTRUE(error_bar)) {
out <- out +
geom_text(aes(label = label), vjust = -1, hjust = 1.2) +
geom_text(aes(label = .data$label), vjust = -1, hjust = 1.2) +
ylim(c(0, max(dat$N) * 1.5))
} else {
out <- out +
geom_text(aes(label = label), vjust = -0.5) +
geom_text(aes(label = .data$label), vjust = -0.5) +
ylim(c(0, max(dat$N) * 1.2))
}
}

# add confidence intervals for frequencies
if (isTRUE(error_bar)) {
out <- out +
geom_errorbar(aes(ymin = lower.ci, ymax = upper.ci), width = 0.5, color = "darkblue")
geom_errorbar(
aes(ymin = .data$lower.ci, ymax = .data$upper.ci),
width = 0.5, color = "darkblue"
)
}

out
Expand Down
8 changes: 6 additions & 2 deletions man/plot.dw_data_tabulate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c05e347

Please sign in to comment.