R - Plotly converts NA label from ggplot2 graphic with a null label

112 views Asked by At

It seems that plotly converts NA values from ggplot2 graphic with a null label. Here is a simple example.

library(ggplot2)
library(plotly)

col1 <- c("a","c","b","c",NA,"a","b","b",NA,NA)
df <- data.frame(col1)

MyPlot <- ggplot(data = df, aes(x = df$col1)) +
  geom_bar(stat = "count")

print(MyPlot)

ggplotly(MyPlot)

MyPlot

Is there a function to override this behavior and keep the NA label ? Maybe with plotly_bluid function who allow changes to the plot ?

1

There are 1 answers

0
MLavoie On BEST ANSWER

You could relabel your ticks by using:

ggplotly(MyPlot) %>% layout(xaxis = list(ticktext = c("a", "b", "c", "na")))