简体   繁体   English

rmarkdown 中的中心 plot_ly 仪表

[英]Center plot_ly gauge in rmarkdown

Can someone help me center my plotly gauges in r markdown?有人能帮我把我的 plotly 仪表放在 r markdown 中吗? Whenever I knit my flexdashboard and open up the HTML file, the plotly gauge values seem to shift while the dial remains centered... how can I make these stagnant/all centered?每当我编织我的 flexdashboard 并打开 HTML 文件时,plotly 仪表值似乎会发生变化,而表盘仍然居中……我怎样才能使这些停滞/全部居中?

gauges仪表

EDIT: here is one of the gauge codes:编辑:这是量规代码之一:

plot_ly(
    type = "indicator",
    mode = "gauge+number",
    align = "center",
    value = round(100*data_open,1),
    number = list(suffix = "%", valueformat = "center", textAlign= 'center'),
    gauge = list(
      font = list(color = "black", family = "Open Sans", size = 16),
        axis = list(
            range = list(0,100),
            tickvals = list(0,20,40,60,80,90,100),
            tickwidth = 1, 
            tickcolor = "black"),
        bar = list(color = "lightgrey", thickness = .20,
                   line = list(width = 4)), 
        borderwidth = 2,
        bordercolor = "lightgrey",
        steps = list(
            list(range = c(0,20), color = "#490f52"),
            list(range = c(20,40), color = "#5d2a65"),
            list(range = c(40,60), color = "#87618d"),
            list(range = c(60,80), color = "#b198b4"),
            list(range = c(80,90), color = "#c6b3c8"),
            list(range = c(90,100), color = "#d7cad9")),         
        threshold = list(
            line = list(color = "darkgrey", width = 4),
            thickness = 0.75,
            value = round(100*data_open,1))),
    height  = 200) %>% 
    layout(margin = list(autoexpand =FALSE, l = 30, r = 45, t = 20, b = 55),
        font = list(color = "black", family = "Open Sans", textAlign= 'center', size = 15)) %>% 
  config(displayModeBar = F)

Your code works nice.您的代码运行良好。

Try to find a problem somewhere on your side (update the packages first of all).尝试在您身边的某个地方找到问题(首先更新软件包)。

Also you can check the c3 package -> https://rdrr.io/cran/c3/ It supports gauges too.您还可以检查c3 package -> https://rdrr.io/cran/c3/它也支持仪表。

```{r}
library(plotly)

plot_ly(
    type = "indicator",
    mode = "gauge+number",
    align = "center",
    value = 50,
    number = list(suffix = "%", valueformat = "center", textAlign= 'center'),
    gauge = list(
      font = list(color = "black", family = "Open Sans", size = 16),
        axis = list(
            range = list(0,100),
            tickvals = list(0,20,40,60,80,90,100),
            tickwidth = 1, 
            tickcolor = "black"),
        bar = list(color = "lightgrey", thickness = .20,
                   line = list(width = 4)), 
        borderwidth = 2,
        bordercolor = "lightgrey",
        steps = list(
            list(range = c(0,20), color = "#490f52"),
            list(range = c(20,40), color = "#5d2a65"),
            list(range = c(40,60), color = "#87618d"),
            list(range = c(60,80), color = "#b198b4"),
            list(range = c(80,90), color = "#c6b3c8"),
            list(range = c(90,100), color = "#d7cad9")),         
        threshold = list(
            line = list(color = "darkgrey", width = 4),
            thickness = 0.75,
            value = 50)),
    height  = 200) %>% 
    layout(margin = list(autoexpand =FALSE, l = 30, r = 45, t = 20, b = 55),
        font = list(color = "black", family = "Open Sans", textAlign= 'center', size = 15)) %>% 
  config(displayModeBar = F)
```

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM