Skip to content

Commit

Permalink
fixed breaking changes
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'origin' into NAtest_construct_label
# Bitte geben Sie eine Commit-Beschreibung ein, um zu erklären, warum dieser
# Merge erforderlich ist, insbesondere wenn es einen aktualisierten
# Upstream-Branch mit einem Thema-Branch zusammenführt.
#
# Zeilen, die mit '#' beginnen, werden ignoriert,
# und eine leere Beschreibung bricht den Commit ab.
  • Loading branch information
nickhaf committed Apr 12, 2024
2 parents 2d4fbe3 + 6719aec commit 9b79efd
Show file tree
Hide file tree
Showing 44 changed files with 402 additions and 405 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Description: Functions for plotting eatModel output.
License: GPL (>= 2)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Suggests:
covr,
knitr,
Expand All @@ -21,7 +21,7 @@ Depends:
R (>= 2.10)
LazyData: true
Imports:
ggbrace,
ggbrace (>= 0.1.1),
ggnewscale,
ggpattern,
ggplot2,
Expand All @@ -32,6 +32,5 @@ Imports:
patchwork,
plyr,
rlang
Remotes: NicolasH2/ggbrace
VignetteBuilder: knitr
URL: https://nickhaf.github.io/eatPlot/
10 changes: 6 additions & 4 deletions R/plot_braces.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ plot_braces <- function(dat,
# Utils -------------------------------------------------------------------
draw_braces <- function(dat, plot_settings = plotsettings_lineplot()) {
if (plot_settings$split_plot == TRUE) {
res <- ggbrace::geom_brace(
res <- ggbrace::stat_brace(
data = unique(dat[, c("years_Trend", "year_axis", "brace_y")]),
mapping = ggplot2::aes(
x = .data$year_axis,
Expand All @@ -64,20 +64,22 @@ draw_braces <- function(dat, plot_settings = plotsettings_lineplot()) {
),
rotate = 180,
linewidth = plot_settings$brace_line_width,
npoints = 200
npoints = 200,
outside = FALSE
)
} else {
res <- lapply(unique(dat$years_Trend), function(x) {
dat_year <- unique(dat[dat$years_Trend == x, c("year_start_axis", "year_end_axis", "upper_y", "lower_y", "mid")])
ggbrace::geom_brace(
ggbrace::stat_brace(
mapping = ggplot2::aes(
x = c(dat_year$year_start_axis, dat_year$year_end_axis),
y = c(dat_year$upper_y, dat_year$lower_y),
),
mid = unique(dat_year$mid),
rotate = 180,
linewidth = plot_settings$brace_line_width,
npoints = 200
npoints = 200,
outside = FALSE
)
})
}
Expand Down
13 changes: 7 additions & 6 deletions R/plot_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ plot_lineplot <- function(plot_dat,
widths_setting <- 1 / plot_settings$n_cols
}

# The wholeGroup plot gets a box drawn around it.
## The wholeGroup plot gets a box drawn around it.
for (plot_names in names(plot_list)) {
if (plot_names %in% seperate_plot_var_box) {
plot_list[[plot_names]] <- plot_list[[plot_names]] +
Expand Down Expand Up @@ -223,19 +223,20 @@ filter_plot_years <- function(plot_dat, years_lines = NULL, years_braces = NULL,
}


plot_title <- function(title, title_raised_letter) {
if (!is.null(title_raised_letter)) {
names(title_raised_letter) <- sapply(names(title_raised_letter), sub_dash)
pos <- which(title == names(title_raised_letter))
plot_title <- function(title, title_superscript) {
if (!is.null(title_superscript)) {
names(title_superscript) <- sapply(names(title_superscript), sub_dash)
pos <- which(title == names(title_superscript))
if (length(pos) == 0) {
ggplot2::labs(title = title)
} else {
superscript <- title_raised_letter[[pos]]
superscript <- title_superscript[[pos]]
ggplot2::labs(title = bquote(.(title)^.(superscript)))
}
} else {
ggplot2::labs(title = title)
}

}


Expand Down
27 changes: 9 additions & 18 deletions R/plot_tablebar.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ plot_tablebar <- function(dat,
dat$y_axis <- rev(as.integer(dat$y_axis))
dat$background_colour <- plot_settings$background_stripes_colour

if(length(plot_settings$bar_nudge_y) != 1 & length(plot_settings$bar_nudge_y) != nrow(dat)){
if (length(plot_settings$bar_nudge_y) != 1 & length(plot_settings$bar_nudge_y) != nrow(dat)) {
stop(paste0("Your plot_settings$bar_nudge_y argument has either to have the length 1, or has to be as long as your data. Currently, it has the length: ", length(plot_settings$bar_nudge_y), ". Your data has: ", nrow(dat), " rows."), call. = FALSE)
}

Expand Down Expand Up @@ -302,7 +302,6 @@ plot_tablebar <- function(dat,
)
}


if (!is.null(bar_est)) {
if (is.null(bar_sig)) {
res_plot <- res_plot +
Expand Down Expand Up @@ -330,10 +329,10 @@ plot_tablebar <- function(dat,
dat <- fill_na(dat, column_name = i, filling = "FALSE")
}


res_plot <- res_plot +
ggnewscale::new_scale_fill() +
ggnewscale::new_scale_colour() +
ggpattern::scale_pattern_manual(values = plot_settings$bar_pattern_type) +
ggplot2::scale_fill_manual(values = plot_settings$bar_fill_colour) +
ggpattern::geom_rect_pattern(
data = dat,
ggplot2::aes(
Expand All @@ -353,12 +352,6 @@ plot_tablebar <- function(dat,
pattern_spacing = plot_settings$bar_pattern_spacing,
pattern_key_scale_factor = 0.6 # legend adjustment
) +
ggpattern::scale_pattern_manual(values = plot_settings$bar_pattern_type) +
ggplot2::scale_colour_manual(values = plot_settings$bar_fill_colour) +
ggplot2::scale_fill_manual(values = plot_settings$bar_fill_colour) +
ggpattern::scale_pattern_manual(values = plot_settings$bar_pattern_type) +
ggplot2::scale_colour_manual(values = plot_settings$bar_fill_colour) +
ggplot2::scale_fill_manual(values = plot_settings$bar_fill_colour) +
NULL
} else if (plot_settings$bar_sig_type == "frame") {
res_plot <- res_plot +
Expand All @@ -384,7 +377,6 @@ plot_tablebar <- function(dat,
}
}


# Column spanners ---------------------------------------------------------
plot_settings <- check_spanners_requirements(column_spanners, column_spanners_2, plot_settings)

Expand Down Expand Up @@ -496,7 +488,6 @@ build_background_stripes <- function(dat,
columns_table,
plot_borders,
plot_settings = plotsettings_tablebarplot()) {

scale_breaks <- set_scale_breaks(plot_borders)

if (plot_settings$background_stripes_border == "Inf") {
Expand Down Expand Up @@ -723,14 +714,14 @@ plot_capped_x_axis <- function(scale_breaks) {
yend = 0.4,
linewidth = 0.1
)
}else{
} else {
## Plot something invisible, so the y axis is the same over all plots:
ggplot2::annotate("segment",
x = 0,
xend = 0,
y = 0.4,
yend = 0.4,
linewidth = 0.00000001
x = 0,
xend = 0,
y = 0.4,
yend = 0.4,
linewidth = 0.00000001
)
}
}
Expand Down
6 changes: 5 additions & 1 deletion R/themes.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ theme_line <- function(plot_settings = plotsettings_lineplot()) {
text = ggplot2::element_text(colour = "#000000"),
panel.spacing = ggplot2::unit(plot_settings$split_plot_gap_width, "npc"), # Gap in split plot
plot.margin = ggplot2::unit(c(0, 0, 0.25, 0), units = "npc"),
plot.title = ggplot2::element_text(size = 7, hjust = 0.5, vjust = 2.5)
plot.title = ggplot2::element_text(size = 7,
hjust = 0.5,
vjust = 0,
margin = ggplot2::margin(-3.5, 0, 3.5, 0)
)
)
}
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ consecutive_numbers <- function(vec) {
#' @keywords internal
#' @noRd
#'
#' @param vec Character vector, usually the group-column in a data.frame returned by [eatRep::report()].
#' @param vec Character vector, usually the group-column in a data.frame returned by `eatRep::report()`.
#' @param groups Character vector of groups that should be extracted from vec.
#'
#' @return Returns the first group found in vec.
Expand Down
8 changes: 4 additions & 4 deletions man/construct_label.Rd

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

Binary file removed tests/adjusted_means_ger.pdf
Binary file not shown.
Binary file removed tests/split_lineplot_2_books.pdf
Binary file not shown.
Binary file removed tests/testplot_1.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/plot_braces/adjacent-braces.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/plot_braces/brace-plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/plot_braces/facetted-braces.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/plot_braces/overlapping-braces.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9b79efd

Please sign in to comment.