【问题标题】:Removing unnecessary labels in the tooptip in R and ggplot2 chart在 R 和 ggplot2 图表的工具提示中删除不必要的标签
【发布时间】:2017-11-14 12:02:04
【问题描述】:

运行下面的 R 和 ggplot2 脚本后,会生成以下快照。将鼠标悬停在任何框上时,我们会得到以下工具提示,如图所示。我的简单要求是去掉第四个 tooltip 属性,因为它类似于第三个。我想需要在下面的 ggplot 命令的 aes() 中做一些事情。另外,如果可以在不增加绘图或字体大小的情况下使文本更清晰,请帮助并感谢。

library(bupaR)
library(ggplot2)
library(scales)
library(plotly)
library(splitstackshape)
tr <- data.frame(traces(patients, output_traces = T, output_cases = F))
tr$Actuals = percent(tr$absolute_frequency/sum(te$absolute_frequency))
tr.df <- cSplit(tr, "trace", ",")
pos <- c(1,4:ncol(tr.df))
tr.df <- tr.df[,..pos]
tr.df <- melt(tr.df, id.vars = "trace_id")
mp1 = ggplot(data = tr.df, aes(x = variable,y = trace_id, fill = value, 
label = value)) + geom_tile(colour = "white") + 
geom_text(colour = "white",  size = 1.9) +
scale_fill_discrete(na.value="transparent") +
theme(legend.position="none") + labs(x = "Traces", y = "Activities")
ggplotly(mp1, height = 500, width = 645)

【问题讨论】:

标签: r ggplot2 plotly ggplotly splitstackshape


【解决方案1】:
library(bupaR)
library(ggplot2)
library(scales)
library(plotly)
library(splitstackshape)
tr <- data.frame(traces(patients, output_traces = T, output_cases = F))
tr$Actuals = percent(tr$absolute_frequency/sum(tr$absolute_frequency))
tr.df <- cSplit(tr, "trace", ",")
pos <- c(1,4:ncol(tr.df))
tr.df <- tr.df[,..pos]
tr.df <- melt(tr.df, id.vars = c("trace_id","Actuals"))

mp1 = ggplot(data = tr.df, aes(x = variable, y = trace_id, fill = value, label = value,
text=paste("Variable:",variable,"<br>Trace ID:",trace_id,"<br>Value:",value,"<br>Actuals:",Actuals))) + 
geom_tile(colour = "white") + 
geom_text(colour = "white",  size = 4) +
scale_fill_discrete(na.value="transparent") +
theme(legend.position="none") + labs(x = "Traces", y = "Activities")

gg <- ggplotly(mp1, tooltip="text")
layout(gg, margin=list(l=50, b=50))

【讨论】:

  • 我现在正在实施点击以提取痕迹,我现在需要你的帮助来处理这篇文章。请帮忙。 stackoverflow.com/questions/47303137/…
  • 那篇文章完全不同,这次我没有改变任何问题。我有一个新要求,涉及您帮助我的跟踪资源管理器。我诚实地向社区寻求帮助。我非常尊重帮助过我的社区成员。
  • 嗨,Marco,我需要你的帮助,在逻辑上进行一些调整以在图中显示数据,请帮我写这篇文章,stackoverflow.com/questions/47951307/…
猜你喜欢
  • 1970-01-01
  • 2011-09-30
  • 2017-08-16
  • 2017-07-06
  • 1970-01-01
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多