問題描述
gvisAnnotatedTimeLine 函數圖表上的標題 (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
參考解法
方法 1:
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
(by h.l.m、Geoffrey Absalom)