# Plotly in R, setting ranges on y-axis

**URL:** <https://community.plotly.com/t/plotly-in-r-setting-ranges-on-y-axis/10570>\
**Category:** Plotly R\
**Created:** [May 29, 2018, 3:33pm UTC](https://community.plotly.com/t/plotly-in-r-setting-ranges-on-y-axis/10570 "2018-05-29T15:33:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![IceRoom](https://avatars.discourse-cdn.com/v4/letter/i/bc79bd/32.png) [@IceRoom](https://community.plotly.com/u/IceRoom)\
**Post date:** [May 29, 2018, 3:33pm UTC](https://community.plotly.com/t/plotly-in-r-setting-ranges-on-y-axis/10570/1 "2018-05-29T15:33:44Z")

</div>

Hi, I have a bar graph in R which is going to be used on powerbi. I want to set a maximum and a minimum to the Y axis. By getting the value entered by the user into ‘Maximum Height’ field or ‘Minimum Height’ field to modify the visualisation.

I set up these two field,  
“yscalemaxin”:{  
“displayName”: “Maximum Height”,  
“displayNameKey”: “dynymax”,  
“type”: {  
“numeric”: true  
}  
},  
“yscaleminin”:{  
“displayName”: “Minimum Height”,  
“displayNameKey”: “dynymin”,  
“type”: {  
“numeric”: true

layout(  
xaxis = list(range = c(0, yscalemaxin)),  
yaxis = list(range = c(yscaleminin, Inf)))  
this code do not work.  
How can I get their values and then the chart changes? I think this function is same as ‘start’ and ‘end’ in PowerBI.

Greetings

---

<div class="post-metadata">

**Author:** ![jerburt](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jerburt](https://community.plotly.com/u/jerburt)\
**Post date:** [May 29, 2018, 6:29pm UTC](https://community.plotly.com/t/plotly-in-r-setting-ranges-on-y-axis/10570/2 "2018-05-29T18:29:20Z")

</div>

Are you trying to do this in a Shiny App or through just the view window?

---

<div class="post-metadata">

**Author:** ![IceRoom](https://avatars.discourse-cdn.com/v4/letter/i/bc79bd/32.png) [@IceRoom](https://community.plotly.com/u/IceRoom)\
**Post date:** [May 30, 2018, 12:26am UTC](https://community.plotly.com/t/plotly-in-r-setting-ranges-on-y-axis/10570/3 "2018-05-30T00:26:52Z")

</div>

Hi, I am trying to do this through the view window

---

<div class="post-metadata">

**Author:** ![bcd](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bcd](https://community.plotly.com/u/bcd)\
**Post date:** [May 30, 2018, 2:32am UTC](https://community.plotly.com/t/plotly-in-r-setting-ranges-on-y-axis/10570/4 "2018-05-30T02:32:05Z")

</div>

Hey @IceRoom

Plotly has custom controls (dropdowns, buttons, and sliders) that you can use to update the layout. For example:

```
library(plotly)

x <- c(1,2,3,4)
y <- c(1,2,3,4)
df <- data.frame(x,y)

p <- plot_ly(df, x = ~x, y = ~y, alpha = 0.3, height = 600, width = 900) %>%
  add_markers() %>%
  layout(
    title = "Use dropdowns to change yaxis range",
    updatemenus = list(
      list(
        y = 0.6,
        buttons = list(
          list(method = "relayout",
               args = list("yaxis.range[0]", 0),
               label = "0"),
          
          list(method = "relayout",
               args = list("yaxis.range[0]", -1),
               label = "-1"),
          
          list(method = "relayout",
               args = list("yaxis.range[0]", -2),
               label = "-2"))),
      list(
        y = 0.725,
        buttons = list(
          list(method = "relayout",
               args = list("yaxis.range[1]", 4),
               label = "4"),
          
          list(method = "relayout",
               args = list("yaxis.range[1]", 5),
               label = "5"),
          
          list(method = "relayout",
               args = list("yaxis.range[1]", 6),
               label = "6")))
    ),
    annotations = list(
      list(
        text='<b>ymin:',
        xref='paper',
        yref='paper',
        x='-0.11',
        y='0.625',
        showarrow=F
      ),
      list(
        text='<b>ymax:',
        xref='paper',
        yref='paper',
        x='-0.11',
        y='0.76',
        showarrow=F
      )
    ))
```
