Skip to content

Commit

Permalink
Change default alpha to NA
Browse files Browse the repository at this point in the history
Thiis fixes geom_text_pairwise() and geom_label_pairwise()
  • Loading branch information
aphalo committed Apr 27, 2024
1 parent 4b51b26 commit 8f02590
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 36 deletions.
4 changes: 2 additions & 2 deletions R/geom-label-linked.r
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ geom_label_s <-
default.color = default.colour,
colour.target = c("text", "box"),
color.target = colour.target,
default.alpha = 1,
default.alpha = NA,
alpha.target = "all",
label.padding = grid::unit(0.25, "lines"),
label.r = grid::unit(0.15, "lines"),
Expand Down Expand Up @@ -114,7 +114,7 @@ GeomLabelS <-
add.segments = TRUE,
default.colour = "black",
colour.target = "all",
default.alpha = 1,
default.alpha = NA,
alpha.target = "fill",
box.padding = 0.25,
point.padding = 1e-06,
Expand Down
6 changes: 3 additions & 3 deletions R/geom-label-pairwise.r
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ geom_label_pairwise <-
default.color = default.colour,
colour.target = "all",
color.target = colour.target,
default.alpha = 1,
default.alpha = NA,
alpha.target = "segment",
label.padding = grid::unit(0.25, "lines"),
label.r = grid::unit(0.15, "lines"),
Expand Down Expand Up @@ -92,7 +92,7 @@ GeomLabelPairwise <-
linetype = "solid",
hjust = 0.5,
vjust = 0.5,
alpha = 1,
alpha = NA,
family = "",
fontface = 1,
lineheight = 1.2
Expand All @@ -104,7 +104,7 @@ GeomLabelPairwise <-
size.unit = "mm",
default.colour = "black",
colour.target = "all",
default.alpha = 1,
default.alpha = NA,
alpha.target = "fill",
segment.linewidth = 0.5,
arrow = NULL,
Expand Down
4 changes: 2 additions & 2 deletions R/geom-point-linked.r
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ geom_point_s <- function(mapping = NULL, data = NULL,
default.color = default.colour,
colour.target = "point",
color.target = colour.target,
default.alpha = 1,
default.alpha = NA,
alpha.target = "all",
add.segments = TRUE,
box.padding = 0.25,
Expand Down Expand Up @@ -222,7 +222,7 @@ GeomPointS <-
move.point = TRUE,
default.colour = "black",
colour.target = "point",
default.alpha = 1,
default.alpha = NA,
alpha.target = "segment",
na.rm = FALSE,
arrow = NULL,
Expand Down
15 changes: 8 additions & 7 deletions R/geom-text-linked.r
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
#' for the segment, assumed not to be used to display information
#' only in coordination with other graphic elements.
#'
#' The default for the \code{alpha = 0.75} aesthetic applied in in
#' \code{geom_label_s()} to the box fill differs from \code{alpha = 1} used in
#' \code{geom_label()}: the fill is semitransparent with with the intention
#' that accidental occlusion of observations is obvious irrespective of the
#' order in which layers are added to the plot.
#' In \code{geom_label_s()} the default \code{fill} is similar to
#' \code{"white"} but with its \code{alpha} component set to 0.75. This
#' differs from \code{"white"} used in \code{geom_label()}: the default fill
#' is semitransparent with the intention that accidental occlusion of
#' observations is obvious irrespective of the order in which layers are added
#' to the plot.
#'
#' Layer functions \code{geom_text_s()} and \code{geom_label_s()} use by
#' default \code{\link{position_nudge_keep}} which is backwards compatible
Expand Down Expand Up @@ -326,7 +327,7 @@ geom_text_s <- function(mapping = NULL,
default.color = default.colour,
colour.target = "text",
color.target = colour.target,
default.alpha = 1,
default.alpha = NA,
alpha.target = "all",
add.segments = TRUE,
box.padding = 0.25,
Expand Down Expand Up @@ -416,7 +417,7 @@ GeomTextS <-
size.unit = "mm",
default.colour = "black",
colour.target = "all",
default.alpha = 1,
default.alpha = NA,
alpha.target = "all",
na.rm = FALSE,
check_overlap = FALSE,
Expand Down
6 changes: 3 additions & 3 deletions R/geom-text-pairwise.R
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ geom_text_pairwise <- function(mapping = NULL,
default.color = default.colour,
colour.target = "all",
color.target = colour.target,
default.alpha = 1,
default.alpha = NA,
alpha.target = "all",
segment.linewidth = 0.5,
arrow = NULL,
Expand Down Expand Up @@ -343,7 +343,7 @@ GeomTextPairwise <-
angle = 0,
hjust = 0.5,
vjust = -0.5,
alpha = 1,
alpha = NA,
family = "",
fontface = 1,
lineheight = 1.2
Expand All @@ -356,7 +356,7 @@ GeomTextPairwise <-
size.unit = "mm",
default.colour = "black",
colour.target = "all",
default.alpha = 1,
default.alpha = NA,
alpha.target = "all",
na.rm = FALSE,
check_overlap = FALSE,
Expand Down
16 changes: 8 additions & 8 deletions R/ggpp-legend-draw.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ draw_key_text_s <- function(data, params, size) {
text.colour <- ifelse(colour2text,
data$colour %||% params$default.colour %||% "black",
params$default.colour %||% "black")
colour.lacks.alpha <- ifelse(nrow(col2rgb(text.colour)) == 3,
colour.lacks.alpha <- ifelse(nrow(grDevices::col2rgb(text.colour)) == 3,
rep(TRUE, length(text.colour)),
is.na(col2rgb(text.colour)[4, ]))
is.na(grDevices::col2rgb(text.colour)[4, ]))
colour.alpha <- ifelse(is.na(data$alpha),
ifelse(colour.lacks.alpha,
params$default.alpha %||% 1,
Expand Down Expand Up @@ -96,9 +96,9 @@ draw_key_label_s <- function(data, params, size) {
text.colour <- ifelse(colour2text,
data$colour %||% params$default.colour %||% "black",
params$default.colour %||% "black")
colour.lacks.alpha <- ifelse(nrow(col2rgb(text.colour)) == 3,
colour.lacks.alpha <- ifelse(nrow(grDevices::col2rgb(text.colour)) == 3,
rep(TRUE, length(text.colour)),
is.na(col2rgb(text.colour)[4, ]))
is.na(grDevices::col2rgb(text.colour)[4, ]))
colour.alpha <- ifelse(is.na(data$alpha),
ifelse(colour.lacks.alpha,
params$default.alpha %||% 1,
Expand Down Expand Up @@ -131,9 +131,9 @@ draw_key_label_s <- function(data, params, size) {
box.colour <- ifelse(colour2box,
data$colour %||% params$default.colour %||% "black",
params$default.colour %||% "black")
colour.lacks.alpha <- ifelse(nrow(col2rgb(box.colour)) == 3,
colour.lacks.alpha <- ifelse(nrow(grDevices::col2rgb(box.colour)) == 3,
rep(TRUE, length(box.colour)),
is.na(col2rgb(box.colour)[4, ]))
is.na(grDevices::col2rgb(box.colour)[4, ]))
colour.alpha <- ifelse(is.na(data$alpha),
ifelse(colour.lacks.alpha,
params$default.alpha %||% 1,
Expand All @@ -150,9 +150,9 @@ draw_key_label_s <- function(data, params, size) {
{
alpha2fill <- any((params$alpha.target %||% "all") %in% c("box", "box.fill", "all"))
box.fill <- data$fill %||% params$default.fill %||% "white"
fill.lacks.alpha <- ifelse(nrow(col2rgb(box.fill)) == 3,
fill.lacks.alpha <- ifelse(nrow(grDevices::col2rgb(box.fill)) == 3,
rep(TRUE, length(box.fill)),
is.na(col2rgb(box.fill)[4, ]))
is.na(grDevices::col2rgb(box.fill)[4, ]))
fill.alpha <- ifelse(is.na(data$alpha),
ifelse(fill.lacks.alpha,
params$default.alpha %||% 1,
Expand Down
2 changes: 1 addition & 1 deletion man/geom_point_s.Rd

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

4 changes: 2 additions & 2 deletions man/geom_text_pairwise.Rd

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

15 changes: 8 additions & 7 deletions man/geom_text_s.Rd

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

2 changes: 1 addition & 1 deletion tests-not/test-label-text-legends.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ggplot(my.cars, aes(wt, mpg, label = name)) +
geom_label_s(aes(size = wt), nudge_x = -0.1, hjust = "right",
fill = "yellow",
colour = "red",
alpha = .7,
alpha = .5,
# default.colour = rgb(0.5,0,0),
colour.target = "none",
alpha.target = "all") +
Expand Down
Binary file modified tests/testthat/Rplots.pdf
Binary file not shown.

0 comments on commit 8f02590

Please sign in to comment.