代码之家  ›  专栏  ›  技术社区  ›  firmo23

跳过plotly条形图中某些条形图中的i相关文本

  •  0
  • firmo23  · 技术社区  · 4 年前

    我创建了一个简单的绘图条形图,但在第一列中,我得到了一个需要删除的奇怪文本。

    library(plotly)
    sum2<-structure(list(month = structure(c(1451606400, 1454284800, 1456790400, 
    1459468800, 1462060800, 1464739200, 1467331200, 1470009600, 1472688000, 
    1475280000), tzone = "UTC", class = c("POSIXct", "POSIXt")), 
        Monthly = c(14236.895, 4519.892, 55691.009, 28295.345, 23648.287, 
        34595.1276, 33946.393, 27909.4685, 81777.3508, 31453.393)), row.names = c(NA, 
    -10L), class = c("tbl_df", "tbl", "data.frame"))
    
    fig <- plot_ly(sum2, x = ~month, y = ~Monthly, type = 'bar', text = text,
                   marker = list(color = 'rgb(158,202,225)',
                                 line = list(color = 'rgb(8,48,107)',
                                             width = 1.5))
    )
    fig <- fig %>% layout( width=1800,height=600
    )
    
    fig
    
    1 回复  |  直到 4 年前
        1
  •  1
  •   Dan Adams    4 年前

    不知道你在做什么 text = text 但是只要去掉那条线,它看起来就好了。

    plot_ly(
      sum2,
      x = ~ month,
      y = ~ Monthly,
      type = 'bar',
      # text = text,
      marker = list(
        color = 'rgb(158,202,225)',
        line = list(color = 'rgb(8,48,107)',
                    width = 1.5)
      )
    )
    

    enter image description here


    这是因为 text 指的是函数 graphics::text() 当不带括号调用时,它只给出具有该名称的对象的报告。试着跑步 文本 在控制台上(没有括号),您将看到什么被作为标签传递到绘图中。

    text
    #> function (x, ...) 
    #> UseMethod("text")
    #> <bytecode: 0x0000000013994f20>
    #> <environment: namespace:graphics>
    

    于2022年2月7日由 reprex package (v2.0.1)