Skip to content

ggplot2 can't determine that Haven labelled integers are discrete #4605

@bholtdwyer

Description

@bholtdwyer

Hi! I'm trying to plot some data from a Haven labelled dataset using ggplot2. I'm grouping by "sex", a labelled int column. However, I get the following:

ggplot() + geom_line(data=dec_by_age_gender, mapping=aes(x=age_5yr,y=avg_dec,group=sex)) + scale_color_manual(values=c("red","green"))

Don't know how to automatically pick scale for object of type haven_labelled/vctrs_vctr/integer. Defaulting to continuous.
> ggplot() + geom_line(data=dec_by_age_gender, mapping=aes(x=age_5yr,y=avg_dec,group=sex)) + scale_color_manual(values=c("red","green"))

Don't know how to automatically pick scale for object of type haven_labelled/vctrs_vctr/integer. Defaulting to continuous.

> head(dec_by_age_gender)
# A tibble: 6 × 3
  age_5yr        sex avg_dec
    <dbl>  <int+lbl>   <dbl>
1      20 1 [Male]   0.00357
2      20 2 [Female] 0.00320
3      25 1 [Male]   0.00421
4      25 2 [Female] 0.00406
5      30 1 [Male]   0.00473
6      30 2 [Female] 0.00453
> class(dec_by_age_gender)
[1] "tbl_df"     "tbl"        "data.frame"
> class(dec_by_age_gender$sex)
[1] "haven_labelled" "vctrs_vctr"     "integer"       
> 

Since "sex" has the class "integer", shouldn't ggplot2 know to pick a discrete color scale for it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorscales 🐍

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions