Description
I have encountered an issue with the current version of ggplot2 (3.5.1) when integrating with the plotly package via the ggplotly function. The provided code should generate a Plotly plot without any errors.
library(plotly)
library(ggplot2)
dat <- data.frame(
time = factor(c("Lunch", "Dinner"), levels = c("Lunch", "Dinner")),
total_bill = c(14.89, 17.23)
)
p <- ggplot(data = dat, aes(x = time, y = total_bill)) +
geom_bar(stat = "identity")
fig <- ggplotly(p)
fig
p2 <- ggplot(data = dat, aes(x = time, y = total_bill, fill = time)) +
geom_bar(stat = "identity")
fig2 <- ggplotly(p2)
fig2
When running the code without an aes() component that generates legend elements (such as color or fill), the plot is created without issues. However, including an aesthetic component that generates a legend (e.g., fill) results in the following error:
Error in train(..., self = self) :
unused argument (list("time", "total_bill", "time"))
This issue appears to be specific to the interaction between ggplot2 and plotly, particularly when using aesthetics that produce legends. In previous versions of ggplot2 this error did not occur. Any insights or resolutions for this problem would be highly appreciated