2
votes

Given for example

library(ggplot2)
library(plotly)
df <- data.frame(V1=gl(6,20), V2=gl(40,3))
p <- ggplot(df, aes(x=V1, fill=V2)) + geom_bar(color="white")
ggplotly(p)

enter image description here

some bar segments show no tooltip/hover information, whereas the legend displays the huge number of factor levels nicely (=scroll bar). How can I fix this?

I'm using

packageVersion("ggplot2")
# [1] ‘2.2.0’
packageVersion("plotly")
# [1] ‘4.5.6’

Edit/FYI: Crossposted to GitHub.

1
I really don't have an answer (maybe because you are only using numbers?) but if you use the diamonds dataset with your code it works: df <- diamonds[sample(1:nrow(diamonds), size = 1000),] ; p <- ggplot(df, aes(x=color, fill=cut)) + geom_bar(color="white"); ggplotly(p)MLavoie
True. I suspect there's a limit in terms of number of levels; the error (?) originally occured with alphanumeric factor levels.lukeA

1 Answers

2
votes

adding some code. We can fix it:

library(ggplot2)
library(plotly)
df <- data.frame(V1=gl(6,20), V2=gl(40,3))
p <- ggplot(df, aes(x=V1, fill=V2)) + geom_bar(color="white")
fixed<-ggplotly(p)

for (i in 1:length(levels(df$V2))){
  fixed$x$data[[i]]$text[length(fixed$x$data[[i]]$text)+1] <- c("")
}
fixed

enter image description here