rshiny水平条形图

时间:2019-12-03 19:51:44

标签: r plotly

我的水平条形图在左上角显示一些黑色凌乱的字母。不知道有人知道为什么吗?

enter image description here

这是代码。我认为这非常简单。我计算每个条目的金额,然后根据数字绘制水平条。

# # data - product hor bar chart
  bv_gmir_hor_bar_data <- reactive({
    inf <- filter_inforce()
    gmir_30_fv <- sum(inf$Fund_val[inf$Buck_min_guar_rate == 0.3])
    gmir_40_fv <- sum(inf$Fund_val[inf$Buck_min_guar_rate == 0.4])
    gmir_85_fv <- sum(inf$Fund_val[inf$Buck_min_guar_rate == 0.85])
    gmir_95_fv <- sum(inf$Fund_val[inf$Buck_min_guar_rate == 0.95])
    gmir_100_fv <- sum(inf$Fund_val[inf$Buck_min_guar_rate == 1])
    gmir_155_fv <- sum(inf$Fund_val[inf$Buck_min_guar_rate == 1.55])
    fv <- sum(inf$Fund_val)
    df <- data.frame(gmir_30_fv,gmir_40_fv,gmir_85_fv,gmir_95_fv,gmir_100_fv,gmir_155_fv,fv)
    return(df)
  })

  # Output - product hor bar chart
  output$bv_gmir_hor_bar <- renderPlotly({
    plot_ly(bv_gmir_hor_bar_data(), x = ~gmir_30_fv, y = 'GMIR: 0.3%', type = 'bar', orientation = 'h', name = 'GMIR: 0.3%', 
            text = ~paste("$", round(gmir_30_fv/1000000,1),"M |",
                          round(100*gmir_30_fv/fv,1),"% | GMIR: 0.3%"), hoverinfo = 'text',
            marker = list(color = 'rgb(204,184,216)',
                          line = list(color = '#000000', width = 1))) %>%
      add_trace(y = 'GMIR: 0.4%', x = ~gmir_40_fv, type = 'bar', orientation = 'h', name = 'GMIR: 0.4%', 
                text = ~paste("$", round(gmir_40_fv/1000000,1),"M |",
                              round(100*gmir_40_fv/fv,1),"% | GMIR: 0.4%"), hoverinfo = 'text',
                marker = list(color = 'rgb(252,216,197)',
                              line = list(color = '#000000', width = 1))) %>%
      add_trace(y = 'GMIR: 0.85%', x = ~gmir_85_fv, type = 'bar', orientation = 'h', name = 'GMIR: 0.85%', 
                text = ~paste("$", round(gmir_85_fv/1000000,1),"M |",
                              round(100*gmir_85_fv/fv,1),"% | GMIR: 0.85%"), hoverinfo = 'text',
                marker = list(color = 'rgb(242,172,189)',
                              line = list(color = '#000000', width = 1))) %>%
      add_trace(y = 'GMIR: 0.95%', x = ~gmir_95_fv, type = 'bar', orientation = 'h', name = 'GMIR: 0.95%', 
                text = ~paste("$", round(gmir_95_fv/1000000,1),"M |",
                              round(100*gmir_95_fv/fv,1),"% | GMIR: 0.95%"), hoverinfo = 'text',
                marker = list(color = 'rgb(211,188,95)',
                              line = list(color = '#000000', width = 1))) %>%
      add_trace(y = 'GMIR: 1.0%', x = ~gmir_100_fv, type = 'bar', orientation = 'h', name = 'GMIR: 1.0%', 
                text = ~paste("$", round(gmir_100_fv/1000000,1),"M |",
                              round(100*gmir_100_fv/fv,1),"% | GMIR: 1.0%"), hoverinfo = 'text',
                marker = list(color = 'rgb(244,238,215)',
                              line = list(color = '#000000', width = 1))) %>%
      add_trace(y = 'GMIR: 1.55%', x = ~gmir_155_fv, type = 'bar', orientation = 'h', name = 'GMIR: 1.55%', 
                text = ~paste("$", round(gmir_155_fv/1000000,1),"M |",
                              round(100*gmir_155_fv/fv,1),"% | GMIR: 1.55%"), hoverinfo = 'text',
                marker = list(color = 'rgb(111,145,111)',
                              line = list(color = '#000000', width = 1))) %>%
        layout(title = "<b>GMIR<b>", titlefont = list(color = '#000000'), 
               paper_bgcolor = '#ffffff', plot_bgcolor = '#ffffff', barmode = 'stack',
               xaxis = list(title = "", color = '#000000', showticklabels = TRUE, gridcolor = '#000000', showgrid = TRUE, side = 'top', dtick = 0.2),
               yaxis = list(title = "", color = '#000000', showticklabels = TRUE, dtick = 1),
               legend = list(x = 0, y = -120, font = list(size = 10, color = '#000000'), orientation = 'h', traceorder = "normal"))

  })

0 个答案:

没有答案