Has anyone had success in customising the tooltip content for gvisTimeline
in the R package googleVis
Scope of need:
I am specifically interested in gvisTimeline
but there are a number of stub questions about tooltips in the other charts of the googleVis
package. I'm collating these in this question for my own reference and in an attempt to provide a useful resource for anyone looking into this:
gvisTreemap
- https://stackoverflow.com/q/30892289/1659890
The Google Charts documentation makes it clear that tooltips are customisable for timelines (but not some charts): https://developers.google.com/chart/interactive/docs/gallery/timeline and https://developers.google.com/chart/interactive/docs/customizing_tooltip_content.
The roles vignettes - https://cran.r-project.org/web/packages/googleVis/vignettes/Using_Roles_via_googleVis.html - highlighted here Shiny - googlevis: Tooltips for gvisPieChart shows how tooltips can be customised for many of the charts in the googlevis
package but does not include gvisTimeline
.
Inspecting the gvis
file on github (https://github.com/mages/googleVis/blob/master/R/gvis.R) shows that any variable including tooltip
will be sent to the Google Chart API. Blindly I attempted to include tooltips into a gvisTimeline
plot as follows, but to no avail:
datTL <- data.frame(Position=c(rep("President", 3), rep("Vice", 3)),
Name=c("Washington", "Adams", "Jefferson",
"Adams", "Jefferson", "Burr"),
start=as.Date(x=rep(c("1789-03-29", "1797-02-03",
"1801-02-03"),2)),
end=as.Date(x=rep(c("1797-02-03", "1801-02-03",
"1809-02-03"),2)),
Position.html.tooltip=c(rep("cats",6)))
Timeline <- gvisTimeline(data=datTL,
rowlabel="Name",
barlabel="Position",
start="start",
end="end")
plot(Timeline)
I was annoyed of Gvistimeline needing internet connection and re-built it using plotly
:
install.packages("vistime")
library(plotly)
library(vistime)
datTL <- data.frame(Position=c(rep("President", 3), rep("Vice", 3)),
Name=c("Washington", "Adams", "Jefferson",
"Adams", "Jefferson", "Burr"),
start=as.Date(x=rep(c("1789-03-29", "1797-02-03",
"1801-02-03"),2)),
end=as.Date(x=rep(c("1797-02-03", "1801-02-03",
"1809-02-03"),2)),
color=c(rep("blue", 3), rep("red", 3)),
fontcolor=rep("white",6),
tooltip=c(rep("cats",6)))
vistime(datTL, events="Position", groups="Name", title="Presidents of the USA")
Tooltips are taken from "tooltip" column. More information: https://github.com/shosaco/vistime
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With