2016-12-16 98 views
2

鉴于例如缺失plotly + GGPLOT2:某些提示以堆叠barplot

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’ 

编辑/ FYI:Crossposted to GitHub

+0

我真的不知道答案(也许是因为你只使用数字?),但如果您使用的钻石,你的代码它的工作原理数据集:DF < - 钻石[样品(1:nrow(钻石),尺寸= 1000)]; p < - ggplot(df,aes(x = color,fill = cut))+ geom_bar(color =“white”); ggplotly(p) – MLavoie

+0

是的。我怀疑在层数方面有限制;错误(?)最初发生在字母数字因子水平。 – lukeA

回答

2

添加一些代码。我们可以解决这个问题:

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

+0

你能解释一下这是什么以及它为什么起作用? –

+0

这是R对象的结构的破解。 – derive111