-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Labels
Description
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