0

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

Ashmin Kaul
  • 860
  • 2
  • 12
  • 37
  • try using `ggplotly(mp1, height = 500, width = 645, tooltip = c("variable","trace_id", "value"))`. Answer is from this thread: https://stackoverflow.com/questions/38733403/edit-labels-in-tooltip-for-plotly-maps-using-ggplot2-in-r – f.lechleitner Nov 14 '17 at 12:10
  • @brettljausn, Hi, I need your help with a little tweak to display data in this post, please help, https://stackoverflow.com/questions/47951307/selection-of-activity-trace-in-a-chart-and-display-in-a-data-table-in-r-shiny – Ashmin Kaul Dec 24 '17 at 14:22

1 Answers1

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

enter image description here

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
  • I am implementing the on-click now to extract traces, I need your help with this post now. Please help. https://stackoverflow.com/questions/47303137/extract-sequence-of-activities-and-display-based-on-click-in-r-plotly – Ashmin Kaul Nov 15 '17 at 09:20
  • That post is completely different and I have not changed any question this time. I have a new requirement involving the trace explorer with which you helped me. I have honestly approached the community for help. I am highly respectful for the community members who have helped me. – Ashmin Kaul Nov 15 '17 at 11:50
  • Hi Marco, I need your help with a little tweak in the logic to display data in the plot, please help me with this post, https://stackoverflow.com/questions/47951307/selection-of-activity-trace-in-a-chart-and-display-in-a-data-table-in-r-shiny – Ashmin Kaul Dec 24 '17 at 14:21