簡體   English   中英

rmarkdown 中的中心 plot_ly 儀表

[英]Center plot_ly gauge in rmarkdown

有人能幫我把我的 plotly 儀表放在 r markdown 中嗎? 每當我編織我的 flexdashboard 並打開 HTML 文件時,plotly 儀表值似乎會發生變化,而表盤仍然居中……我怎樣才能使這些停滯/全部居中?

儀表

編輯:這是量規代碼之一:

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)

您的代碼運行良好。

嘗試在您身邊的某個地方找到問題(首先更新軟件包)。

您還可以檢查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