plotly + ggplot2:堆叠barplot中缺少一些工具提示 [英] plotly + ggplot2: Some tooltips missing in stacked barplot
本文介绍了plotly + ggplot2:堆叠barplot中缺少一些工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
library(ggplot2)
library(绘图)
df < - 数据帧(V1 = gl(6,20),V2 = gl(40,3))
p <-ggplot(df,aes(x = V1,fill = V2))+ geom_bar(color =白色)
ggplotly(p)
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:堆叠barplot中缺少一些工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文