如何在R中显示gvisTimeline的工具提示,我的代码是:
library(googleVis)
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=paste('<p><nobr>', format(round(c(0.460, 5.100,
2.393,2.3,2.2,3.33), 2), nsmall = 2), 'm<sup>3</sup></nobr></p>'))
Timeline <- gvisTimeline(datTL,
rowlabel="Name",
barlabel="Position",
start="start",
end="end",
options=list(tooltip="{isHtml:'true'}") )
plot(Timeline)
未显示工具提示。
感谢WhiteHat
datTL <- data.frame(
Name=c("Washington", "Adams", "Jefferson",
"Adams", "Jefferson", "Burr"),
Position=c(rep("President", 3), rep("Vice", 3)),
Position.html.tooltip=paste('<p><nobr>', format(round(c(0.460, 5.100,
2.393,2.3,2.2,3.33), 2), nsmall = 2), 'm<sup>3</sup></nobr></p>'),
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))
)
Timeline <- gvisTimeline(datTL,
rowlabel="Name",
barlabel=c("Position","Position.html.tooltip" ),
start="start",
end="end",
options=list(tooltip="{isHtml:'true'}")
)
plot(Timeline)
根据我在R中的经验,第一部分的顺序并不重要,我们需要在数据框中放置Position.html.tooltip(即datTL $ Position.html.tooltip),然后将其放置在barbel中,如上面第二部分所示