From 407dfd980a15ebf9e665a4b6e578aff2041a9ac5 Mon Sep 17 00:00:00 2001 From: njtierney Date: Mon, 4 May 2026 17:05:53 +1000 Subject: [PATCH] remove a lot of unrequired hjust=0 duplicates --- R/vis-dat.R | 3 +-- R/vis-expect.R | 18 ++++++++-------- R/vis-guess.R | 3 +-- R/vis-histogram.R | 4 ++-- R/vis-miss.R | 55 ++++++++++++++++++++++------------------------- R/vis-value.R | 1 - 6 files changed, 39 insertions(+), 45 deletions(-) diff --git a/R/vis-dat.R b/R/vis-dat.R index 77becaf..bb25153 100644 --- a/R/vis-dat.R +++ b/R/vis-dat.R @@ -110,8 +110,7 @@ vis_dat <- function( # change the limits etc. ggplot2::guides(fill = ggplot2::guide_legend(title = "Type")) + # add info about the axes - ggplot2::scale_x_discrete(limits = col_order_index, position = "top") + - ggplot2::theme(axis.text.x = ggplot2::element_text(hjust = 0)) + ggplot2::scale_x_discrete(limits = col_order_index, position = "top") if (!missing(facet)) { vis_dat_plot <- vis_dat_plot + diff --git a/R/vis-expect.R b/R/vis-expect.R index 3459d12..dffa425 100644 --- a/R/vis-expect.R +++ b/R/vis-expect.R @@ -95,9 +95,6 @@ vis_expect <- function(data, expectation, show_perc = TRUE) { ggplot2::ggplot(ggplot2::aes(x = variable, y = rows)) + ggplot2::geom_raster(ggplot2::aes(fill = valueType)) + ggplot2::theme_minimal() + - ggplot2::theme( - axis.text.x = ggplot2::element_text(angle = 45, vjust = 1, hjust = 1) - ) + ggplot2::labs(x = "", y = "Observations") + # flip the axes ggplot2::scale_y_reverse() + @@ -110,15 +107,18 @@ vis_expect <- function(data, expectation, show_perc = TRUE) { "grey" ), labels = c(p_expect_false_lab, p_expect_true_lab), + # light gray na.value = "#E5E5E5" - ) + # light gray - ggplot2::guides(fill = ggplot2::guide_legend(reverse = TRUE)) + + ) + # change the limits etc. - ggplot2::guides(fill = ggplot2::guide_legend(title = "Expectation")) + + ggplot2::guides( + fill = ggplot2::guide_legend( + title = "Expectation", + reverse = TRUE + ) + ) + # add info about the axes - ggplot2::theme(legend.position = "bottom") + - # ggplot2::theme(axis.text.x = ggplot2::element_text(hjust = 0.5)) + - ggplot2::theme(axis.text.x = ggplot2::element_text(hjust = 0)) + ggplot2::theme_sub_legend(position = "bottom") vis_expect_plot } diff --git a/R/vis-guess.R b/R/vis-guess.R index 31d9c58..4c1bd6c 100644 --- a/R/vis-guess.R +++ b/R/vis-guess.R @@ -57,8 +57,7 @@ vis_guess <- function(x, palette = "default") { vis_plot <- vis_create_(d) + ggplot2::guides(fill = ggplot2::guide_legend(title = "Type")) + # flip the axes, add info for axes - ggplot2::scale_x_discrete(position = "top", limits = names(x)) + - ggplot2::theme(axis.text.x = ggplot2::element_text(hjust = 0)) + ggplot2::scale_x_discrete(position = "top", limits = names(x)) # specify a palette ---------------------------------------------------------- add_vis_dat_pal(vis_plot, palette) diff --git a/R/vis-histogram.R b/R/vis-histogram.R index 2a924d9..dc2b0d6 100644 --- a/R/vis-histogram.R +++ b/R/vis-histogram.R @@ -34,7 +34,7 @@ vis_histogram_create <- function(data, ...) { ggplot2::theme_minimal() + ggplot2::labs(x = "", y = "") + ggplot2::guides(fill = ggplot2::guide_legend(title = "Histogram")) + - ggplot2::theme( - axis.text.x = ggplot2::element_text(angle = 45, hjust = 0.1) + ggplot2::theme_sub_axis_x( + text = ggplot2::element_text(angle = 45, hjust = 0.1) ) } diff --git a/R/vis-miss.R b/R/vis-miss.R index a81742f..f6dbc16 100644 --- a/R/vis-miss.R +++ b/R/vis-miss.R @@ -140,37 +140,34 @@ vis_miss <- function( ) ) + ggplot2::guides(fill = ggplot2::guide_legend(reverse = TRUE)) + - ggplot2::theme(legend.position = "bottom") + - # fix up the location of the text - ggplot2::theme(axis.text.x = ggplot2::element_text(hjust = 0)) - - # add the missingness column labels - - # if there is only one colummn you don't need to sort the columns - # this is perhaps a bit of a hacky way around, but I can't see another - # way around it. Related issue: https://github.com/ropensci/visdat/issues/72 - if (ncol(x) == 1) { - if (show_perc_col) { - return( - vis_miss_plot <- vis_miss_plot + - ggplot2::scale_x_discrete( - position = "top", - labels = label_col_missing_pct( - x_fingerprinted, - col_order_index + ggplot2::theme_sub_legend(position = "bottom") + + # add the missingness column labels + + # if there is only one colummn you don't need to sort the columns + # this is perhaps a bit of a hacky way around, but I can't see another + # way around it. Related issue: https://github.com/ropensci/visdat/issues/72 + if (ncol(x) == 1) { + if (show_perc_col) { + return( + vis_miss_plot <- vis_miss_plot + + ggplot2::scale_x_discrete( + position = "top", + labels = label_col_missing_pct( + x_fingerprinted, + col_order_index + ) ) - ) - ) - } else if (!show_perc_col) { - return( - vis_miss_plot <- vis_miss_plot + - ggplot2::scale_x_discrete( - position = "top", - labels = col_order_index - ) - ) + ) + } else if (!show_perc_col) { + return( + vis_miss_plot <- vis_miss_plot + + ggplot2::scale_x_discrete( + position = "top", + labels = col_order_index + ) + ) + } } - } if (!missing(facet)) { vis_miss_plot <- vis_miss_plot + diff --git a/R/vis-value.R b/R/vis-value.R index 35a95fe..b0f9397 100644 --- a/R/vis-value.R +++ b/R/vis-value.R @@ -42,6 +42,5 @@ vis_value <- function(data, na_colour = "grey90", viridis_option = "D") { ggplot2::guides(fill = ggplot2::guide_legend(title = "Value")) + # add info about the axes ggplot2::scale_x_discrete(position = "top") + - ggplot2::theme(axis.text.x = ggplot2::element_text(hjust = 0)) + ggplot2::scale_fill_viridis_c(option = viridis_option, na.value = na_colour) }