【问题标题】:Vertical line appearing when manually adjust x-axis range using plotly使用 plotly 手动调整 x 轴范围时出现垂直线
【发布时间】:2021-07-13 00:01:26
【问题描述】:

我正在使用 plotly 创建图表,并希望将 x 轴扩展到 0。但是,由于某种原因,当我这样做时,会在 0 处绘制垂直参考线,如下所示。有没有办法省略这条线,让 0 处的垂直线简单地出现灰色线其他网格线?

library(dplyr)
library(plotly)

mtcars %>% 
  mutate(cyl = factor(cyl)) %>% 
  plot_ly(
    x = ~mpg, 
    y = ~cyl,
    type = "scatter",
    mode = "markers"
  ) %>% 
  layout(xaxis = list(
    range = c(0, 35)
  ))

【问题讨论】:

    标签: r plotly r-plotly


    【解决方案1】:

    默认plotly会自动绘制zeroline。这可以通过layout 参数zeroline 打开和关闭。如果您想要零线,您可以通过zerolinecolor="#eee" 将颜色设置为等于网格线的颜色,其中#eee 是默认网格线颜色。见the docs

    library(dplyr)
    library(plotly)
    
    mtcars %>% 
      mutate(cyl = factor(cyl)) %>% 
      plot_ly(
        x = ~mpg, 
        y = ~cyl,
        type = "scatter",
        mode = "markers"
      ) %>% 
      layout(xaxis = list(
        range = c(0, 35), 
        zeroline = FALSE
        #zerolinecolor = "#eee"
      ))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-19
      • 2019-01-10
      • 2016-02-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-26
      相关资源
      最近更新 更多