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

Geom.vline not having the same color as shown in the legend #1577

Open
rkmalaiya opened this issue Apr 25, 2022 · 2 comments
Open

Geom.vline not having the same color as shown in the legend #1577

rkmalaiya opened this issue Apr 25, 2022 · 2 comments

Comments

@rkmalaiya
Copy link

Hello,
My apologies if this is not the right place to discuss this situation I am facing while using Geom.vline(). Also, not sure if this is a bug in the Gadfly package or in my code.

I want to make density plots of 2 different normal distributions and I want to use Geom.vline to represent the mean of these density plots. And I am using different colors to represent the densities. The density plots follow the same color as in the legend, but vline doesn't do that. Please advise

x1 = rand(Normal(0,1), 1000)
x2 = rand(Normal(1,1), 1000)

Gadfly.plot(
    layer(x=x1, color = ["Population 1"], Geom.density),
    layer(x=x2, color = ["Population 2"], Geom.density),
    layer(xintercept = [mean(x1)], Geom.vline, color = ["Population 1"]),
    layer(xintercept = [mean(x2)], Geom.vline, color = ["Population 2"])

    )

The plot I get is below. Both of the vline's show the same "blue" color.

image

The issue still exists if I just make a single density plot and use vline for the mean

x1 = rand(Normal(0,1), 1000)
Gadfly.plot(
    x=x1,
    Geom.density, color = ["density"],
    layer(xintercept = [mean(x1)], Geom.vline, color = ["mean"])
)

image

Thanks for the help!

@rkmalaiya rkmalaiya changed the title Geom.vline not having the same color as the legends shows Geom.vline not having the same color as shown in the legend Apr 25, 2022
@Rapsodia86
Copy link

Yeah, indeed it does not capture the vline geometry color.
As a temporal solution, you may try defining a color for Geom.vline() and set manual scale color & legend:

Gadfly.plot(layer(x=x1, Geom.density, color=["density"]),
layer(xintercept=[mean(x1)], Geom.vline(color=["red"])),
Scale.color_discrete_manual("blue", "red", levels=["density", "mean"])
)

image

@rkmalaiya
Copy link
Author

Thank you @Rapsodia86 for the solution, it helps.

I am assuming that I should keep the issue open so that it gets fixed.

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