Skip to content
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

Fix regression in geom_sf() #6190

Merged
merged 1 commit into from
Nov 27, 2024
Merged

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6189.

Briefly, ggraph::GeomEdgeSf did not have a stroke aesthetic in GeomEdgeSf$default_aes.
That causes some calculations to go awry in GeomSf$draw_panel().
This PR makes a fallback for when stroke is missing.

devtools::load_all("~/packages/ggplot2/")
library(ggraph)

gr <- sfnetworks::as_sfnetwork(sfnetworks::roxel)
ggraph(gr, 'sf') + geom_edge_sf()

Created on 2024-11-19 with reprex v2.1.1

@yutannihilation
Copy link
Member

The current CRAN version looks up the default value of GeomLine. Maybe this is better than using the fixed value 0.5? Or, as this is just a safeguard to prevent the error, is it too much?

ggplot2/R/geom-sf.R

Lines 192 to 204 in 8fa3974

defaults <- list(
GeomPoint$default_aes,
GeomLine$default_aes,
modify_list(GeomPolygon$default_aes, list(fill = "grey90", colour = "grey35", linewidth = 0.2))
)
defaults[[4]] <- modify_list(
defaults[[3]],
rename(GeomPoint$default_aes, c(size = "point_size", fill = "point_fill"))
)
default_names <- unique0(unlist(lapply(defaults, names)))
defaults <- lapply(setNames(default_names, default_names), function(n) {
unlist(lapply(defaults, function(def) def[[n]] %||% NA))
})

stroke <- (x$stroke %||% defaults$stroke[1]) * .stroke / 2

@teunbrand
Copy link
Collaborator Author

In my mind, this is pureley to prevent an error. I'm happy to take a default from elsewhere, but the default value in in GeomLine/GeomPath is dynamic:

linewidth = from_theme(linewidth),

At the point the safeguard is introduced, we don't have access to the theme, so we can't compute this default at that point. Ideally, ggraph::GeomEdgeSf$default_aes includes a stroke aesthetic.

@yutannihilation
Copy link
Member

yutannihilation commented Nov 27, 2024

we don't have access to the theme, so we can't compute this default at that point

Ah, makes sense.

Ideally, ggraph::GeomEdgeSf$default_aes includes a stroke aesthetic.

Agreed.

@teunbrand teunbrand merged commit 949d359 into tidyverse:main Nov 27, 2024
13 checks passed
@teunbrand
Copy link
Collaborator Author

Thank you for the review!

@teunbrand teunbrand deleted the sf_regression branch November 27, 2024 08:31
@agila5
Copy link

agila5 commented Nov 27, 2024

cc @loreabad6. I don't understand all details, but maybe you are interested in the conversation above and may decide to adjust the ggraph code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Github version broke geom_edge_sf from ggraph
3 participants