r - 如何绘制彼此相邻的绘图仪表图?

标签 r plotly subplot flexdashboard gauge

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

最佳答案

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

关于r - 如何绘制彼此相邻的绘图仪表图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61164966/

相关文章:

python - 将线图添加到 Facetgrid 图中

python - Matplotlib:获取和设置轴位置

r - 在 R 中列出没有子文件夹的文件夹中的所有文件

r - 在构面变量上设置..count ..总和

r - 使用 devtools 构建包 - 抛出错误,其中 "Author"和 "Maintainer"字段尽管已填充但仍丢失/为空

r - Shiny 的 plotlyOutput() 不响应高度和宽度大小

python - 如何在不在 iPython 笔记本中的离线模式下使用 plotly 进行绘图?

r - 如何在 rgl 中绘制具有交互作用的回归平面

javascript - 调整大小并使 PotlyJS 的 fiddle 图表响应

python - 如何从 Matplotlib 中的两个轴取消设置 `sharex` 或 `sharey`