预先感谢您提供的任何建议!我希望能够在面向公众的交互式情节的工具提示中重新标记“计数”。
这是一个可重现的示例:
library(plotly)
df <- data.frame(cat=c(rep("A", 5), rep("B", 7), rep("C", 10)),
time=c(rep("Time1", 3), rep("Time2", 13), rep("Time3", 6)))
ggplotly(ggplot(df, aes(x=time, fill=cat)) + geom_bar(position = "fill"))
我知道我可以使用 控制工具提示中的时间和类别标签text=paste("Category:", cat, "Time:" time)
,但似乎无法弄清楚如何为计数提供更美观的标题。
谢谢你的时间!
也许有一个更简单的解决方案,但你可以这样做:
library(plotly)
df <- data.frame(cat=c(rep("A", 5), rep("B", 7), rep("C", 10)),
time=c(rep("Time1", 3), rep("Time2", 13), rep("Time3", 6)))
gg <- ggplotly(ggplot(df, aes(x=time, fill=cat)) + geom_bar(position = "fill"))
ggg <- plotly_build(gg)
for(i in 1:length(ggg$x$data)){
text <- ggg$x$data[[i]]$text
text <- gsub("count:", "Count:", text)
text <- gsub("time:", "Time:", text)
text <- gsub("cat:", "Cat:", text)
ggg$x$data[[i]]$text <- text
}
ggg
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句