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

ggplotly() creates a wrong legend in some cases #2420

Open
aloboa opened this issue Feb 2, 2025 · 1 comment
Open

ggplotly() creates a wrong legend in some cases #2420

aloboa opened this issue Feb 2, 2025 · 1 comment

Comments

@aloboa
Copy link

aloboa commented Feb 2, 2025

Given

d1 <- data.frame(X=1:10, Y= (1:10)^2, b=paste0("B",1:10),d="d1")
d2 <- d1
d2$Y <- d1$Y+2
d2$d <- "d2"
d <- rbind(d1,d2)
gg2 <- ggplot(data=d) +
  geom_point(data=d[d$d=="d1",],aes(x=X, y=Y, label=b,col=d)) +
  geom_line(data=d[d$d=="d2",],aes(x=X, y=Y,col=d))

print(gg) results in:

Image

But
ggplotly(gg)

results in:

Image

I know a more conventional code such as:

d <- rbind(d1,d2)
gg <- ggplot(data=d) +
  geom_point(data=d[d$d=="d1",],aes(x=X, y=Y, label=b,col=d)) +
  geom_line(data=d[d$d=="d2",],aes(x=X, y=Y,col=d))
print(gg)
ggplotly(gg)

results in similar legends, but I wonder if the 1st example is not uncovering a bug in ggplotly()

@romanzenka
Copy link

Your more conventional code block appears identical to the first block, except in the first one you refer to gg2 variable and print gg... is that a mistake on your end?

The label=b generates a warning "Ignoring unknown aesthetics: label".

The "conventional" code block works.

Can you revise your first code block and provide code that actually fails for you? It appears to me that you accidentally copied the functional code twice.

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

No branches or pull requests

2 participants