6

It seems like plotly gauge charts are not compatible with subplot because I end up with two gauge charts on top of each other.

library(plotly)

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

fig1

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

fig2

fig <- subplot(fig1,fig2)
fig
SRL
  • 145
  • 9

1 Answers1

5

The x and y values defined in the domain is overriding any other layout options.

Use the x and y definitions to specify the gauge locations:

library(plotly)

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

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

fig <- subplot(fig1, fig2)
fig

enter image description here

Dave2e
  • 22,192
  • 18
  • 42
  • 50
  • Do you know why the gauges don't autosize when used with subplot, but other plots will? In Plotly's basic subplot example, the domain is not specified (https://plotly.com/r/subplots/) – SRL Apr 12 '20 at 18:07
  • No, I don't. I am with you on learning the ins and outs of Plotly. It is a powerful tool, but it has its' quirks. – Dave2e Apr 12 '20 at 20:56
  • Here is an ok reference, https://plotly.com/python/indicator/, it for Python, (The R page is unavailable), it provides a basic guide. – Dave2e Apr 13 '20 at 17:40