googleVis 中的格式工具提示

Format tooltip in googleVis

我想在 googleVis 图表的 tooltip 中格式化数字(添加 big.mark)。昨天我问了这个问题: 得到了答案。今天,我遇到了非常相似的问题 - 不同之处在于有不止一组,所以添加 tooltip 不起作用......

我的问题的可视化:

我的代码:

ui.R:

library("shiny")
library("googleVis")

shinyUI(fluidPage(

    htmlOutput("wyk")

))

server.R:

library("shiny")
library("googleVis")
library("dplyr")

shinyServer(function(input, output) {

    d <- iris %>%
        group_by(Species) %>%
        summarise(ile=1e6*sum(Sepal.Length),
                  ile2=1e6*sum(Petal.Length))

    output$wyk <- renderGvis({
        gvisBarChart(d, xvar = "Species", yvar = c("ile", "ile2"),
                     options=list(legend="top", bar="{groupWidth:'90%'}", height=500))
    })
})

如有任何帮助,我将不胜感激!

您可以使用 roles 执行此操作,这是一个示例:

library("shiny")
library("googleVis")

d <- iris %>%
        group_by(Species) %>%
        summarise(ile=1e6*sum(Sepal.Length),
                  ile2=1e6*sum(Petal.Length))

d$ile.html.tooltip <- prettyNum(d$ile,big.mark = ",",scientific = F)
d$ile2.html.tooltip <- prettyNum(d$ile2,big.mark = ",",scientific = F)

ggvis_plot <- gvisBarChart(d, xvar = "Species", yvar = c("ile","ile.html.tooltip","ile2","ile2.html.tooltip"),
                     options=list(legend="top", bar="{groupWidth:'90%'}", height=500))

plot(ggvis_plot)