0

运行下面的 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)

跟踪图

4

1 回答 1

0
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))

在此处输入图像描述

于 2017-11-14T21:51:52.800 回答