Skip to content

Conversion of discrete labels fails if they come from a factor #1772

Closed
@dmurdoch

Description

@dmurdoch

This StackOverflow question https://stackoverflow.com/q/61888967/2554330 motivated this report.

If the labels in scale_x_discrete are a factor, ggplot works fine. This is okay:

ggplot(diamonds, aes(cut)) + 
  geom_bar() + 
  scale_x_discrete("Cut", labels=factor(letters[1:5]))

However, ggplotly() fails:

ggplotly(
  ggplot(diamonds, aes(cut)) + 
  geom_bar() + 
  scale_x_discrete("Cut", labels=factor(letters[1:5]))
)
#> Error in nchar(axisObj$ticktext): 'nchar()' requires a character vector

Apparently an as.character() call is needed when ticktext is constructed.

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