Skip to content

Inconsistent facet labeller behaviour when using characters to facet #1070

@naught101

Description

@naught101
library(data.table)
library(ggplot2)

# Labeller function
iris_lblr <- function(var, value) {
    labels <- c('setosa'='SET', 'versicolor'='VERS', 'virginica'='VIRG')
        if (var=='Species') {
            return ( labels[value])
        }
}

# using data.table just for ease of filtering/mutation
dt <- data.table(iris)

# This plot works fine - short caps labels are applied correctly
ggplot(dt, aes(x=Sepal.Length, y=Petal.Length)) + geom_point() + facet_grid(.~Species, labeller=iris_lblr)

# this plot also has the correct CAPS labels applied, and the middle facet is missing
ggplot(dt[Species!='versicolor'], aes(x=Sepal.Length, y=Petal.Length)) + geom_point() + facet_grid(.~Species, labeller=iris_lblr)

dt[, Species:=as.character(Species)]

# This plot shows "VERS" where it should show "VIRG". 
ggplot(dt[Species!='versicolor'], aes(x=Sepal.Length, y=Petal.Length)) + geom_point() + facet_grid(.~Species, labeller=iris_lblr)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions