Как построить сюжетные диаграммы рядом друг с другом? - PullRequest
3 голосов
/ 12 апреля 2020

Кажется, что графические диаграммы не совместимы с subplot, потому что я получаю две измерительные диаграммы друг на друга.

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

1 Ответ

2 голосов
/ 12 апреля 2020

Значения x и y, определенные в домене, имеют приоритет над любыми другими параметрами макета.

Используйте определения x и y, чтобы указать положения датчика:

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

...