2

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

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
h.l.m
  • 13,015
  • 22
  • 82
  • 169
  • 1
    In alot of cases I use html and css to label plots from googlevis. – Seth Aug 06 '12 at 01:53
  • Sorry, I'm not familiar with html or css, can you give me a quick example of the code in `R` needed to do that, as I'm not sure where I would go about starting to put in the html code so that the titles appear...thanks...furthermore...would this work if you have used `gvisMerge` to put together a bunch of `gvisAnnotatedTimeLine` graphs, and you wanted the title on each of them? – h.l.m Aug 06 '12 at 02:01

1 Answers1

0

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
Geoffrey Absalom
  • 1,815
  • 15
  • 16