Skip to content

Error when calling scale_linetype (where no error was present previously) #6669

@bockthom

Description

@bockthom

I stumbled upon an error in the scale_linetype function and its internal invocation of discrete_scale. When calling the function with aesthetics = "edge_linetype", I observe the following error (which I suspect to be related to palette being NULL in this case):

Error in `as_discrete_pal()`:
! Cannot convert `x` to a discrete palette.

Note, however, that the error does not occur if aesthetics is omitted or changed, e.g., to linetype. Furthermore, it does not appear when we manually call discrete_scale with aesthetics = "edge_linetype" as soon as we provide a palette. Here is minimal code to reproduce the bug:

library(igraph)
library(ggraph)
library(ggplot2)
library(scales)

network = igraph::make_graph(c("A", "B"))

# works
plot = ggraph::ggraph(network)
plot = plot + ggplot2::scale_linetype(aesthetics = "linetype")
print(plot)

# works
plot = ggraph::ggraph(network)
plot = plot + ggplot2::scale_linetype()
print(plot)

# works
plot = ggraph::ggraph(network)
plot = plot + ggplot2::discrete_scale(aesthetics = "edge_linetype", palette = scales::pal_linetype())
print(plot)

# breaks
plot = ggraph::ggraph(network)
plot = plot + ggplot2::scale_linetype(aesthetics = "edge_linetype")
print(plot)

This error has not been present prior to the release of version 4.0.0 of ggplot2


Cc: @hechtlC @maxloeffler

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions