如何在 R 中的 Gauge meter 中添加百分比标记

How to add percentage mark to value in Gauge meter in R plotly

  output$col3<-renderPlotly({
    fig <- plot_ly(type = "indicator",mode = "gauge+number",value=VTE_cal(),height = 265,
      gauge = list(axis = list(range = list(NULL,100),tickwidth = 1, tickcolor = "black"),
        bar = list(color = "darkblue"),bgcolor = "white",borderwidth = 2,bordercolor = "gray",
        steps = list(list(range = c(0,20), color = "red"),list(range = c(20,40), color = "pink"),list(range = c(40,60), color = "yellow"),list(range = c(60,80), color = "gold"),list(range = c(80,100), color = "teal")),
        threshold = list(line = list(color = "black", width = 4),thickness = 0.75,value = VTE_cal())))
    fig <- fig %>%layout(margin = list(l=30,r=50),paper_bgcolor = "lavender",font = list(color = "black", family = "Arial"))
           # annotations=list(showarrow=T,arrowhead=3,arrowsize=1,arrowwidth=4))
    fig
  })

您可以使用number参数为value指定前缀或后缀;这是一个示例(缩进正确!)

plot_ly(
    type = "indicator",
    mode = "gauge+number",
    value = 86,
    number = list(suffix = "%"),    # <- Specify `prefix` or `suffix`
    gauge = list(
        axis = list(
            range = list(NULL,100),
            tickwidth = 1, 
            tickcolor = "black"),
        bar = list(color = "darkblue"),
        bgcolor = "white", 
        borderwidth = 2,
        bordercolor = "gray",
        steps = list(
            list(range = c(0,20), color = "red"),
            list(range = c(20,40), color = "pink"),
            list(range = c(40,60), color = "yellow"),
            list(range = c(60,80), color = "gold"),
            list(range = c(80,100), color = "teal")),
        threshold = list(
            line = list(color = "black", width = 4),
            thickness = 0.75,
            value = 86))) %>%
    layout(
        margin = list(l = 30, r = 50),
        paper_bgcolor = "lavender",
        font = list(color = "black", family = "Arial"))