rplotly

Plotly indicator plot for specific values


Code bellow gives me plot for value 20 from 30.

How can I change max of this plot (in my example 30)?

library(plotly)

fig <- plot_ly(
  domain = list(x = c(0, 1), y = c(0, 1)),
  
 value = 20,
  title = list(text = "Speed"),
  type = "indicator",
  mode = "gauge+number"
 )
fig <- fig %>%
  layout(margin = list(l=2,r=3))

fig

Solution

  • You can set the range of the gauge like so:

    library(plotly)
    
    fig <- plot_ly(
      domain = list(x = c(0, 1), y = c(0, 1)),
      value = 20,
      title = list(text = "Speed"),
      type = "indicator",
      mode = "gauge+number",
      gauge = list(
        axis = list(
          range = c(0, 40)
        )
      )
    )
    
    fig <- fig %>%
      layout(margin = list(l = 50, r = 50))
    
    fig