0
votes

Upon running the R and ggplot2 script below, the following snapshot is generated. Upon hovering on any box, we get the following tooltip as shown in the plot. My simple requirement is to get rid of the fourth tooltip attribute as it is similar to the third . I guess something needs to be done in the aes() of ggplot command below.Also if the text can be made more clear without increasing the size of the plot or font, please help and thanks.

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)

Trace Chart

1
try using ggplotly(mp1, height = 500, width = 645, tooltip = c("variable","trace_id", "value")). Answer is from this thread: stackoverflow.com/questions/38733403/…brettljausn
@brettljausn, Hi, I need your help with a little tweak to display data in this post, please help, stackoverflow.com/questions/47951307/…Ashmin Kaul

1 Answers

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

enter image description here