Skip to content

Commit

Permalink
fixed cropped text with float contrast TRUE
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberosa committed Oct 29, 2024
1 parent b36b04d commit 5a0c5c8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 48 deletions.
4 changes: 2 additions & 2 deletions R/002_plot_components.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ add_scaling_component_to_delta_plot <- function(delta_plot, float_contrast, boot
ggplot2::coord_cartesian(
ylim = c(min_y_coords, min_y_coords + delta_y_range),
xlim = c(1.8, delta_x_max + 0.4 + delta_text_space),
expand = FALSE
# clip = "off"
expand = FALSE,
clip = "off"
) +
ggplot2::scale_x_continuous(
breaks = c(2),
Expand Down
18 changes: 12 additions & 6 deletions R/002_plot_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,10 @@ add_delta_text_to_delta_plot <- function(delta_plot,
}

y_coordinates <- y_values
if (float_contrast) {
# Adding a bit extra space not to touch the horizontal lines
y_coordinates <- y_coordinates + 0.01
}
if (!is.null(params_delta_text$y_coordinates)) {
y_coordinates <- params_delta_text$y_coordinates
}
Expand All @@ -616,13 +620,15 @@ add_delta_text_to_delta_plot <- function(delta_plot,
delta_text_colours <- colours[x_values]
}
labels <- sprintf("%+.2f", y_values)

# Prepare the text for each coordinate
texts <- data.frame(
x = x_coordinates + x_adjust, # Replace with your specific x-coordinate
y = y_coordinates, # Replace with your specific y-coordinate
text = sprintf("%+.2f", y_values),
group = delta_text_colours
)

# custom colour
if (!is.null(custom_colour)) {
delta_plot <- delta_plot +
Expand All @@ -640,15 +646,15 @@ add_delta_text_to_delta_plot <- function(delta_plot,
)
} else if (main_violin_type == "multicolour") {
for (i in seq_along(x_coordinates)) {
x <- x_coordinates[i] + x_adjust
y <- y_coordinates[i]
label <- labels[i]
x_i <- x_coordinates[i] + x_adjust
y_i <- y_coordinates[i]
label_i <- labels[i]
text_colour <- delta_text_colours[i]
delta_plot <- delta_plot + ggplot2::geom_text(
data = texts,
x = x,
y = y,
label = label,
x = x_i,
y = y_i,
label = label_i,
colour = text_colour,
alpha = alpha,
check_overlap = TRUE,
Expand Down
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.
Loading

0 comments on commit 5a0c5c8

Please sign in to comment.