问题
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)
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:
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
来源:https://stackoverflow.com/questions/41184959/plotly-ggplot2-some-tooltips-missing-in-stacked-barplot