Search code examples
rggplot2ggplotly

How to rename many variables in ggplotly?


How to rename many variables in ggplotly?

When I scroll over the interactive graphs, the names are not pleasant to look at. I want to format them to include spacing, etc.


Solution

  • You can do it with a tibble, the tidyverse's take on the data.frame.

    library(tibble)
    my_tbl <- tibble(`Nice variable 1` = runif(10),
                     `Special?Characters?` = runif(10),
                     `:)` = runif(10))
    my_tbl
    

    Use my_tbl as input to your ggplot object e.g. ggplot(data = my_tbl) then wrap that ggplot object with ggplotly.