Kumpelka
Kumpelka

Reputation: 987

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

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 ?

Upvotes: 0

Views: 113

Answers (1)

MLavoie
MLavoie

Reputation: 9886

You could relabel your ticks by using:

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

Upvotes: 1

Related Questions