h.l.m
h.l.m

Reputation: 13475

Title on chart for gvisAnnotatedTimeLine function

I am using the gvisAnnotatedTimeLine function from the googleVis package, and was wondering if there was a way of adding in a Title (not an annotation) into the output, as I can't see an argument for it in the function help file.

Thanks in advance

Upvotes: 2

Views: 663

Answers (1)

Geoffrey Absalom
Geoffrey Absalom

Reputation: 1895

Here is a function that should include a title to the chart. The input is either an HTML string or a shiny.tag.

addGvisATLTitle <- function(gvisATL,title)  {

if (!all(class(gvisATL) == c("gvis","list"))) {
  stop('ERROR in addGvisATLTitle: Incorrect type, expect gvisAnnotatedTimeLine.')
}
if (class(title) == "character") {
  gvisATL$html$chart['divChart'] <- paste(title,gvisATL$html$chart['divChart'],sep="")
} else if (class(title) == "shiny.tag") {
  gvisATL$html$chart['divChart'] <- paste(as.character(title)[1],gvisATL$html$chart['divChart'],sep="")
} else {
  stop('ERROR in addGvisATLTitle: Unknown title type.')
}
return(gvisATL)
}

you can test it out with

 a <- data.frame(date=Sys.Date(),val=20)
 b <- gvisAnnotatedTimeLine(a)
 plot(addTitle(b,"<h1> My chart </h1>"))
 plot(addTitle(b,h1("My chart")))
  • I have updated it to work with gvisMerge

Upvotes: 0

Related Questions