Skip to content

Unable to use fixed alpha aesthetic when color is mapped to a factor #1932

@logworthy

Description

@logworthy

I'm trying to use a fixed alpha aesthetic to manually highlight points in a plot. It fails when color is mapped to a factor.

library(ggplot2)
data(mtcars)

# fails (but should work)
ggplot(mtcars, aes(x=disp, y=hp, color=as.factor(cyl)))+geom_point(alpha=seq(0,1,length.out=32))
# Error: Aesthetics must be either length 1 or the same as the data (3): alpha

# fails (and should fail)
ggplot(mtcars, aes(x=disp, y=hp, color=as.factor(cyl)))+geom_point(alpha=seq(0,1,length.out=3))
# Error: Aesthetics must be either length 1 or the same as the data (32): alpha

# succeeds
ggplot(mtcars, aes(x=disp, y=hp, color=cyl))+geom_point(alpha=seq(0,1,length.out=32))

Tested on version 2.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions