Skip to content

alpha needs a scale and a legend even with discrete variables #98

@jiho

Description

@jiho

Consider this use case, where I plot a series over rectangles which represent a binary response

d <- data.frame(x=1:50, y=runif(50), z=rep(c(T,F,T,T,F), each=10))
ggplot(d) + geom_rect(aes(xmin=x-0.5, xmax=x+0.5, ymin=-Inf, ymax=Inf, fill=z)) + geom_path(aes(x=x, y=y))

Rather than the color, I would prefer to have "something" when z is TRUE et nothing when z is FALSE (simpler, clearer, etc.). So:

ggplot(d) + geom_rect(aes(xmin=x-0.5, xmax=x+0.5, ymin=-Inf, ymax=Inf, alpha=z)) + geom_path(aes(x=x, y=y))

but then I have no way of knowing which is which because there is no legend... So I did:

ggplot(d) + geom_rect(aes(xmin=x-0.5, xmax=x+0.5, ymin=-Inf, ymax=Inf, fill=z, alpha=z)) + geom_path(aes(x=x, y=y))

But even then, the legend does not reflect the transparency of the FALSE parts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions