Skip to content

linetype of geom_edge_arc can't be factor anymore with ggplot2 v4 (3.5.2.9002 main branch) #394

Open

Description

@pwwang
packageVersion("ggplot2")
packageVersion("ggraph")

graph
df_nodes

library(ggraph)

p <- ggraph(graph, layout = "manual", x = df_nodes$x, y = df_nodes$y) +
    geom_edge_arc(aes(color = I(node.gender), linewidth = friendship, linetype = factor(type)))

p

With ggplot2 v3.5.2 (CRAN):

[1] ‘3.5.2’
[1] ‘2.2.2’
Image
Image

With ggplot2 v3.5.2.9002 (main branch):

[1] ‘3.5.2.9002’
[1] ‘2.2.2’
Image
ERROR while rich displaying an object: Error in `as_discrete_pal()`:
Cannot convert `x` to a discrete palette.

Traceback:
1. sapply(x, f, simplify = simplify)
2. lapply(X = X, FUN = FUN, ...)
3. FUN(X[[i]], ...)
4. tryCatch(withCallingHandlers({
 .     if (!mime %in% names(repr::mime2repr)) 
 .         stop("No repr_* for mimetype ", mime, " in repr::mime2repr")
 .     rpr <- repr::mime2repr[[mime]](obj)
 .     if (is.null(rpr)) 
 .         return(NULL)
 .     prepare_content(is.raw(rpr), rpr)
 . }, error = error_handler), error = outer_handler)
5. tryCatchList(expr, classes, parentenv, handlers)
6. tryCatchOne(expr, names, parentenv, handlers[[1L]])
7. doTryCatch(return(expr), name, parentenv, handler)
8. withCallingHandlers({
 .     if (!mime %in% names(repr::mime2repr)) 
 .         stop("No repr_* for mimetype ", mime, " in repr::mime2repr")
 .     rpr <- repr::mime2repr[[mime]](obj)
 .     if (is.null(rpr)) 
 .         return(NULL)
 .     prepare_content(is.raw(rpr), rpr)
 . }, error = error_handler)
9. repr::mime2repr[[mime]](obj)
10. repr_text.default(obj)
11. paste(capture.output(print(obj)), collapse = "\n")
12. capture.output(print(obj))
13. withVisible(...elt(i))
14. print(obj)
15. `print.ggplot2::ggplot`(obj)
16. ggplot_build(x)
17. ggplot_build.ggraph(x)
18. NextMethod()
19. `ggplot_build.ggplot2::ggplot`(x)
20. npscales$set_palettes(plot@theme)
21. set_palettes(..., self = self)
22. as_discrete_pal(elem)
23. as_discrete_pal.default(elem)
24. cli::cli_abort("Cannot convert {.arg x} to a discrete palette.")
25. rlang::abort(message, ..., call = call, use_cli_format = TRUE, 
  .     .frame = .frame)
26. signal_abort(cnd, .file)

Attaching the graph and df_nodes data for debugging.

data.zip

Related: pwwang/plotthis#21

Activity

  1. teunbrand commented on Oct 10, 2025

    @teunbrand
    Collaborator

    Smaller, self-contained reprex:

    library(ggraph)
    library(tidygraph)
    
    gr <- create_notable('bull') |>
      activate(edges) |>
      mutate(g = sample(letters[1:3], n(), replace = TRUE))
    
    ggraph(gr, 'stress') +
      geom_edge_link(aes(linetype = g))
    #> Error in `as_discrete_pal()`:
    #> ! Cannot convert `x` to a discrete palette.

    Created on 2025-10-10 with reprex v2.1.1

    Should be fixed by tidyverse/ggplot2#6674.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions