Mohsen Sichani
Mohsen Sichani

Reputation: 1076

tooltip in R by gvisTimeline, googleVis

How can I show a tooltip by gvisTimeline in R, my code is:

  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)

No tooltip is shown.

Upvotes: 1

Views: 48

Answers (1)

Mohsen Sichani
Mohsen Sichani

Reputation: 1076

Thanks to 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)

Based on my experience in R, the order of the first part is not important, we need to have Position.html.tooltip in the dataframe(i.e. datTL$Position.html.tooltip) and then have this in the barbel as shown above in the second part

Upvotes: 1

Related Questions