2

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.

2
  • 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) Commented Dec 16, 2016 at 16:57
  • True. I suspect there's a limit in terms of number of levels; the error (?) originally occured with alphanumeric factor levels. Commented Dec 16, 2016 at 17:10

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Could you maybe explain what this does and why it works?
It is a hack of the estructure of the R object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.