密谋:如何在次要Y轴上设置最小值?

时间:2020-08-01 20:58:17

标签: r graph plotly axis-labels r-plotly

我想在次要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

我得到这个: enter image description here

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

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

1 个答案:

答案 0 :(得分:1)

通常,如果您已经设置了npm install node-sass -D

fig

在您的特定情况下:

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

情节

enter image description here

完整代码:

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