【问题标题】:How to plot plotly gauge charts next to each other?如何绘制彼此相邻的图表?
【发布时间】:2020-07-24 15:48:54
【问题描述】:

似乎情节仪表图表与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

【问题讨论】:

    标签: r plotly subplot flexdashboard gauge


    【解决方案1】:

    域中定义的 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
    

    【讨论】:

    • 你知道为什么仪表在与子图一起使用时不会自动调整大小,但其他图会吗?在 Plotly 的基本子图示例中,未指定域 (plotly.com/r/subplots)
    • 不,我不知道。我和你一起学习 Plotly 的来龙去脉。它是一个强大的工具,但它有它的“怪癖”。
    • 这是一个好的参考,plotly.com/python/indicator,它用于 Python,(R 页面不可用),它提供了一个基本指南。
    最近更新 更多