The labels are not showing on the Gauge

Hello, I am trying to place the labels on the gauge using Plotly library, but I can't make it happen. Could someone point me in the right direction, thanks.

Find below the code and the screenshot of my result.

library(plotly)

fig <- plot_ly(
domain = list(x = c(0, 1), y = c(0, 1)),
value = 65,
type = "indicator",
mode = "label+gauge+number",
label = c("Wages", "Operating expenses", "Cost of sales", "Insurance"),
gauge = list(
axis =list(range = list(0, 100)),
bgcolor = "white",
steps = list(
list(range = c(0, 60), color = "green"),
list(range = c(60,80), color = "yellow"),
list(range = c(80,100), color = "red")),
font = list(size = 24, color = "white", family = "Open Sans")
))

fig <- fig %>%
layout(
margin = list(l=20,r=30),
paper_bgcolor = "#0D0D0D",
font = list(color = "white", family = "Open Sans"))
fig

Screenshot 2022-07-20 105431

type indicator does not support a label param and there is no such mode as label+gauge+number; so if additional text is needed you have to use a different approach, and there may be an appropriate one, but first please explain, where would these text labels appear in relation to your gauge chart ? Before I can try to write code to a solution, it helps to have a good visual image in imagination of what we are trying to achieve.

The most direct way available is to label the ticks, something like

library(plotly)

fig <- plot_ly(
  domain = list(x = c(0, 1), y = c(0, 1)),
  value = 65,
  type = "indicator",
  mode = "gauge+number",
  gauge = list(
    axis =list(range = list(0, 100),
               tickmode="array",
               tickvals=c(0,20,40,60,80,100),
               ticktext=c("0: Wages","20", "40","60: Operating expenses", "80: Cost of sales", "100: Insurance")),
    bgcolor = "white",
    steps = list(
      list(range = c(0, 60), color = "green"),
      list(range = c(60,80), color = "yellow"),
      list(range = c(80,100), color = "red")),
    font = list(size = 24, color = "white", family = "Open Sans")
  )) %>%
  layout( 
    margin = list(l=100,r=100),
    paper_bgcolor = "#0D0D0D",
    font = list(color = "white", family = "Open Sans"))
fig

Hello, thank you for your response. I would like the labels to be added to the different thresholds.

Below you will find a screenshot of the kind of gauge chart I am trying to achieve.

Screenshot 2022-07-14 220655

I anticipated that and provided an example, hope it helps you.

Thank you very much, yes it worked.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.