plotly + ggplot2:堆叠条形图中缺少一些工具提示 [英] plotly + ggplot2: Some tooltips missing in stacked barplot
本文介绍了plotly + ggplot2:堆叠条形图中缺少一些工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
举个例子
库(ggplot2)图书馆(情节)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)
一些条形段没有显示工具提示/悬停信息,而图例很好地显示了大量因子级别(=滚动条).我怎样才能解决这个问题?
我正在使用
packageVersion("ggplot2")# [1] ‘2.2.0’packageVersion(情节")# [1] ‘4.5.6’
编辑/仅供参考:
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.
解决方案
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
这篇关于plotly + ggplot2:堆叠条形图中缺少一些工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文