Skip to content

Compatibility with ggplot2 4.0.0 #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
linters: linters_with_defaults(
cyclocomp_linter = NULL,
commented_code_linter = NULL,
line_length_linter = NULL,
object_name_linter = NULL,
seq_linter = NULL
seq_linter = NULL,
return_linter = NULL
)
exclusions:
list(
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ Description:
plot networks.
Depends:
R (>= 3.1),
ggplot2 (>= 3.4.4)
ggplot2 (>= 3.5.2)
Imports:
dplyr (>= 1.0.0),
tidyr (>= 1.3.0),
grDevices,
grid,
ggstats,
ggstats (>= 0.9.0),
gtable (>= 0.2.0),
lifecycle,
plyr (>= 1.8.3),
Expand Down Expand Up @@ -71,7 +71,7 @@ Suggests:
emmeans,
vdiffr
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
SystemRequirements: openssl
Encoding: UTF-8
Language: en-US
Expand Down
8 changes: 7 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# GGally (development version)

* Prepare GGally for ggplot2 v4 (Thank you @teunbrand! #528)


# GGally 2.2.1

* Fix compatibility with ggplot2 3.5.0 (@teunbrand, #481)
* Fix compatibility with ggplot2 3.5.0 (Thank you @teunbrand! #481)


# GGally 2.2.0

Expand All @@ -28,6 +32,7 @@
* Replace `ggplot2` usage of `*_guide = FALSE` with `*_guide = "none"` (@larmarange, #418)
* Require `network >= 1.17.1` (#418)


# GGally 2.1.1

### Bug fixes
Expand All @@ -37,6 +42,7 @@
* Avoid an error when tidiers do not return p-values. (@larmarange, #400)
* Suggest `emmeans` to allow `ggcoef()` example to execute. (#407)


# GGally 2.1.0

### Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion R/gg-plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ ggally_count <- function(data, mapping, ...) {
args <- list(...)
if (!"fill" %in% names(args)) {
if (is.null(mapping$fill)) {
args$fill <- GeomRect$default_aes$fill
args$fill <- get_geom_defaults(GeomRect)$fill
}
}

Expand Down
2 changes: 1 addition & 1 deletion R/ggally_cross.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ggally_cross <- function(data, mapping, ..., scale_max_size = 20, geom_text_args
args$shape <- 22
}
if (is.null(mapping$fill) && is.null(args$fill)) {
args$fill <- GeomRect$default_aes$fill
args$fill <- get_geom_defaults(GeomRect)$fill
}
args$keep.zero.cells <- FALSE

Expand Down
4 changes: 2 additions & 2 deletions R/ggcoef.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ ggcoef <- function(
}
}
if (conf.int && "conf.low" %in% names(x) && "conf.high" %in% names(x)) {
p <- p + geom_errorbarh(
p <- p + geom_errorbar(
aes(xmin = !!as.name("conf.low"), xmax = !!as.name("conf.high")),
color = errorbar_color,
height = errorbar_height,
width = errorbar_height,
linetype = errorbar_linetype,
linewidth = errorbar_size
)
Expand Down
34 changes: 2 additions & 32 deletions R/gglyph.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ glyphs <- function(
x_scale = identity) {
data$gid <- interaction(data[[x_major]], data[[y_major]], drop = TRUE)

if (is.rel(width)) {
if (inherits(width, "rel")) {
width <- resolution(data[[x_major]], zero = FALSE) * unclass(width)
message("Using width ", format(width, digits = 3))
}

if (is.rel(height)) {
if (inherits(height, "rel")) {
height <- resolution(data[[y_major]], zero = FALSE) * unclass(height)
message("Using height ", format(height, digits = 3))
}
Expand Down Expand Up @@ -207,36 +207,6 @@ print.glyphplot <- function(x, ...) {
# cat("\n")
}


# Relative dimensions --------------------------------------------------------

# Relative dimensions
#
# @param x numeric value between 0 and 1
# rel <- function(x) {
# structure(x, class = "rel")
# }
# @export
# rel <- ggplot2::rel

# @rdname rel
# @param ... ignored
# print.rel <- function(x, ...) {
# print(noquote(paste(x, " *", sep = "")))
# }
## works even though it is not exported
# @export
# ggplot2::print.rel

# @rdname rel
# is.rel <- function(x) {
# inherits(x, "rel")
# }
## only used internally. and ggplot2 has this exported
# @export
# ggplot2:::is.rel
is.rel <- ggplot2:::is.rel

# Rescaling functions --------------------------------------------------------

#' Rescaling functions
Expand Down
2 changes: 1 addition & 1 deletion R/ggmatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ggmatrix <- function(
byrow = byrow
)

attributes(plotMatrix)$class <- c("gg", "ggmatrix")
attributes(plotMatrix)$class <- c("ggmatrix", "gg")

plotMatrix
}
Expand Down
2 changes: 1 addition & 1 deletion R/ggmatrix_gtable.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ ggmatrix_gtable <- function(
}

# if it's not a ggplot2 obj, insert it and pray it works
if (!is.ggplot(p)) {
if (!is_ggplot(p)) {
pmg$grobs[[grob_pos_panel]] <- p
next
}
Expand Down
20 changes: 12 additions & 8 deletions R/ggpairs_add.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#' @param e2 A component to add to \code{e1}
#'
#' @export
#' @seealso [ggplot2::+.gg] and [ggplot2::theme()]
#' @method + gg
#' @rdname gg-add
#' @examples
Expand All @@ -44,19 +43,24 @@
#' p_(pm + extra)
"+.gg" <- function(e1, e2) {
if (!is.ggmatrix(e1)) {
return(e1 %+% e2)
if ("add_gg" %in% getNamespaceExports("ggplot2")) {
fn <- utils::getFromNamespace("add_gg", "ggplot2")
} else {
fn <- ggplot2::`%+%`
}
return(fn(e1, e2))
}

if (is.null(e1$gg)) {
e1$gg <- list()
}
if (inherits(e2, "labels")) {
if (inherits(e2, c("labels", "ggplot2::labels"))) {
add_labels_to_ggmatrix(e1, e2)
} else if (is.theme(e2)) {
} else if (is_theme(e2)) {
add_theme_to_ggmatrix(e1, e2)
} else if (is.list(e2)) {
add_list_to_ggmatrix(e1, e2)
} else if (is.ggproto(e2)) {
} else if (is_ggproto(e2)) {
add_to_ggmatrix(e1, e2)
} else {
stop(
Expand Down Expand Up @@ -97,7 +101,7 @@ add_labels_to_ggmatrix <- function(e1, e2) {

if (length(non_ggmatrix_labels) > 0) {
if (is.null(e1$gg$labs)) {
e1$gg$labs <- structure(list(), class = "labels")
e1$gg$labs <- labs()
}
e1$gg$labs[non_ggmatrix_labels] <- e2[non_ggmatrix_labels]
}
Expand All @@ -114,7 +118,7 @@ add_theme_to_ggmatrix <- function(e1, e2) {
e1$gg$theme <- e2
} else {
# calls ggplot2 add method and stores the result in gg
e1$gg$theme <- e1$gg$theme %+% e2
e1$gg$theme <- e1$gg$theme + e2
}
e1
}
Expand Down Expand Up @@ -148,7 +152,7 @@ add_to_ggmatrix <- function(
if (!is.ggmatrix(e1)) {
stop("e1 should be a ggmatrix.")
}
if (!is.ggproto(e2)) {
if (!is_ggproto(e2)) {
stop("e2 should be a ggproto object.")
}

Expand Down
2 changes: 1 addition & 1 deletion R/ggpairs_getput.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ getPlot <- function(pm, i, j) {
if (is.null(plotObj)) {
p <- ggally_blank()
} else {
if (ggplot2::is.ggplot(plotObj)) {
if (ggplot2::is_ggplot(plotObj)) {
p <- plotObj
} else if (inherits(plotObj, "ggmatrix_plot_obj")) {
fn <- plotObj$fn
Expand Down
2 changes: 1 addition & 1 deletion R/ggpairs_internal_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ str.ggmatrix <- function(object, ..., raw = FALSE) {
"'str(", objName, ", raw = TRUE)'\n\n"
))
obj$plots <- lapply(obj$plots, function(plotObj) {
if (ggplot2::is.ggplot(plotObj)) {
if (ggplot2::is_ggplot(plotObj)) {
str_c("PM; ggplot2 object; mapping: ", mapping_as_string(plotObj$mapping))
} else if (inherits(plotObj, "ggmatrix_plot_obj")) {
as.character(plotObj)
Expand Down
2 changes: 0 additions & 2 deletions man/gg-add.Rd

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

2 changes: 1 addition & 1 deletion man/reexports.Rd

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

Loading
Loading