r - plotly + ggplot2 : Some tooltips missing in stacked barplot

标签 r ggplot2 plotly

举个例子

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

一些条形图段不显示工具提示/悬停信息,而图例则很好地显示了大量的因子水平(=滚动条)。我怎样才能解决这个问题?

我正在使用

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

编辑/仅供引用:Crossposted to GitHub

最佳答案

添加一些代码。我们可以修复它:

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

关于r - plotly + ggplot2 : Some tooltips missing in stacked barplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41184959/

相关文章:

r - R 可以将表情符号字符转换为对应的文本吗?

r - gsub 查找模式

r - 迭代 lapply 时打印列表名称

r - 优化这个 for 循环(字母到数字)函数的最佳方法是什么?

r - 如何使用ggplot绘制多因子列?

R:如何跨区域可视化给定列中的前 5 个值

r - 切换两个小面条标签的位置并跨列合并一个标签

plotly - 如何在绘图中不填充 NaN 下的区域

r - 图为Sankey图:如何更改节点的默认顺序

R 子图大小不一致