Plotly:如何在次要 y 轴上设置最小值?

Plotly: How to set a minimum value on secondary y-axis?

我想在次要 y 轴上设置一个最小值。这是我的代码:

library(plotly)

# my data
value <- c(300000,400000,500000,600000,500000,600000)
x1 <- c(3,4,5,5,4,3)
x2 <-c(3,4,5,5,4,3)
name <- c("martin","john","marc","igor","thea","julia")
df <- data.frame(value, x1, x2, name)


# graph with plotly
graph=df %>% 
  plot_ly(x = ~name) %>% 
  add_bars(y = ~x1,
           name = "bar1") %>% 
  add_bars(y = ~x2,
           name = "bar2") %>%
  add_lines(y = ~value,
            name = "line",
            yaxis = "y2") %>% 
  layout(barmode = "bar",
         yaxis2 = list(overlaying = "y",
                       side = "right"),
         barmode = "bar",
         legend = list(x = 1.1, y =1))

# showing graph
  graph

我明白了:

但我希望辅助 y 轴从 200k(或 100k)开始而不是 300k。

我们该如何解决?一些帮助将不胜感激

一般来说,如果您已经 fig 设置:

fig <- fig %>% layout(yaxis2 = list(range = c(<min>, <max>)))

在您的具体情况下:

graph <- graph %>% layout(yaxis2 = list(range = c(200000,600000)))

情节

完整代码:

library(plotly)

# my data
value <- c(300000,400000,500000,600000,500000,600000)
x1 <- c(3,4,5,5,4,3)
x2 <-c(3,4,5,5,4,3)
name <- c("martin","john","marc","igor","thea","julia")
df <- data.frame(value, x1, x2, name)


# graph with plotly
graph=df %>% 
  plot_ly(x = ~name) %>% 
  add_bars(y = ~x1,
           name = "bar1") %>% 
  add_bars(y = ~x2,
           name = "bar2") %>%
  add_lines(y = ~value,
            name = "line",
            yaxis = "y2") %>% 
  layout(barmode = "bar",
         yaxis2 = list(overlaying = "y",
                       side = "right"),
         barmode = "bar",
         legend = list(x = 1.1, y =1))

# showing graph
#graph

graph <- graph %>% layout(yaxis2 = list(
      #scaleanchor = "x",
      #scaleratio = 0.2,
      range = c(200000,600000)
      #title = "1:5"
      ))
graph