0

I have created the following bullet chart in R

library(plotly)
fig<-plot_ly() 
fig <- fig %>%  
add_trace(
type = "indicator",
mode = "number+gauge+delta",
value = 35,
delta = list(reference = 100),
domain = list(x = c(0.25, 1), y = c(0.4, 0.6)),
title = list(text = "Avalue"),
gauge = list(shape = "bullet",axis = list(range = list(NULL, 100)),threshold = list(       
line = list(color = "black", width= 2), thickness = 0.75,value = 55),steps = list(
    list(range = c(0, 25), color = "red"),
    list(range = c(25, 50), color = "blue"),
    list(range = c(50, 75), color = "green"),
    list(range = c(75, 100), color = "grey")),
    bar = list(color = "grey"))) 

How do I remove the whitespace around the chart. And is there a way I can adjust the length of the chart

Raghavan vmvs
  • 1,213
  • 1
  • 10
  • 29

1 Answers1

1

You should change your values for your domain in the add_trace. I changed the y to FALSE and x to a different range, which results in the following plot:

library(plotly)
fig<-plot_ly() 
fig <- fig %>%  
  add_trace(
    type = "indicator",
    mode = "number+gauge+delta",
    value = 35,
    delta = list(reference = 100),
    domain = list(x = c(0.1, 1), y = FALSE),
    title = list(text = "Avalue"),
    gauge = list(shape = "bullet",axis = list(range = list(NULL, 100)),threshold = list(       
      line = list(color = "black", width= 2), thickness = 0.75,value = 55),steps = list(
        list(range = c(0, 25), color = "red"),
        list(range = c(25, 50), color = "blue"),
        list(range = c(50, 75), color = "green"),
        list(range = c(75, 100), color = "grey")),
      bar = list(color = "grey"))) 
fig

Output:

enter image description here

As you can see, the whitespace is way less.

Quinten
  • 35,235
  • 5
  • 20
  • 53