【问题标题】:Anyway to remove the 0 on the y-axis in Plotly R graph?无论如何要删除Plotly R图中y轴上的0?
【发布时间】:2021-09-10 20:28:19
【问题描述】:

我有这个简单的图形,我正在用 plotly 制作。

library(plotly)
fig <- plot_ly(x = ~rnorm(50), type = "histogram")

fig

这是输出。

但我的目标是 - y 轴上没有 0。

【问题讨论】:

    标签: r plotly ggplotly


    【解决方案1】:

    这可以通过布局选项手动设置tickvalsticktext 来实现。请注意,您必须选择tickmode="array"。一个缺点是这会在左侧和顶部增加一些额外的空间,因此您必须另外手动设置边距。

    library(plotly)
    
    set.seed(42)
    x <- rnorm(50)
    fig <- plot_ly(x = ~x, type = "histogram")
    
    fig %>% 
      layout(yaxis = list(
        tickvals = as.list(seq(0, 20, 2)),
        ticktext = as.list(c("", seq(2, 20, 2))),
        tickmode = "array"
      ), margin = list(l = 2, t = 2))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-01
      • 2021-04-16
      • 2020-03-20
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多