I am trying to make a grid display of several plotly gauge charts in R and am having trouble getting the coordinates right. I would like to display 9 gauge charts in a 3x3 grid. Whenever I try, the charts overlay each other. I am not super familiar with specifying the domain, so having trouble finding the right coordinates to specify.
I have tried using the subplot() function, and it is able to align some of them, but whenever I try to mess around with the settings, it overlays the charts. I could only get 4 to line up (shown in example 1), but need 3x3. Example 2 shows when I try to manipulate it further.
Example 1
library(plotly)
fig1 <- plot_ly(
domain = list(x = c(0, 0.45), y = c(0, 0.5)),
value = 270,
title = list(text = "Plot 1"),
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, 0.5)),
value = 50,
title = list(text = "Plot 2"),
type = "indicator",
mode = "gauge+number")
fig2 <- fig2 %>% layout(margin = list(l=20,r=30))
fig3 <- plot_ly(
domain = list(x = c(0, 0.45), y = c(0.5, 1)),
value = 50,
title = list(text = "Plot 3"),
type = "indicator",
mode = "gauge+number")
fig3 <- fig3 %>% layout(margin = list(l=20,r=30))
fig4 <- plot_ly(
domain = list(x = c(0.55, 1), y = c(0.5, 1)),
value = 50,
title = list(text = "Plot 4"),
type = "indicator",
mode = "gauge+number")
fig4 <- fig4 %>% layout(margin = list(l=20,r=30))
fig <- subplot(fig1, fig2, fig3, fig4)
fig
Example 2
library(plotly)
fig1 <- plot_ly(
domain = list(x = c(0.25, 0), y = c(0, 0.5)),
value = 270,
title = list(text = "Plot 1"),
type = "indicator",
mode = "gauge+number")
fig1 <- fig1 %>% layout(margin = list(l=20,r=30))
fig2 <- plot_ly(
domain = list(x = c(0.50, 0), y = c(0, 0.5)),
value = 50,
title = list(text = "Plot 2"),
type = "indicator",
mode = "gauge+number")
fig2 <- fig2 %>% layout(margin = list(l=20,r=30))
fig3 <- plot_ly(
domain = list(x = c(0.75, 0), y = c(0, 0.5)),
value = 50,
title = list(text = "Plot 3"),
type = "indicator",
mode = "gauge+number")
fig3 <- fig3 %>% layout(margin = list(l=20,r=30))
fig4 <- plot_ly(
domain = list(x = c(0.55, 1), y = c(0.5, 1)),
value = 50,
title = list(text = "Plot 4"),
type = "indicator",
mode = "gauge+number")
fig4 <- fig4 %>% layout(margin = list(l=20,r=30))
fig <- subplot(fig1, fig2, fig3, fig4)
fig