# Zoom into an area of a line graph without touching the axes on the top and bottom

**URL:** <https://community.plotly.com/t/zoom-into-an-area-of-a-line-graph-without-touching-the-axes-on-the-top-and-bottom/61684>\
**Category:** Plotly R\
**Tags:** tips-and-tricks\
**Created:** [March 7, 2022, 5:22am UTC](https://community.plotly.com/t/zoom-into-an-area-of-a-line-graph-without-touching-the-axes-on-the-top-and-bottom/61684 "2022-03-07T05:22:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashim](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@ashim](https://community.plotly.com/u/ashim)\
**Post date:** [March 7, 2022, 5:22am UTC](https://community.plotly.com/t/zoom-into-an-area-of-a-line-graph-without-touching-the-axes-on-the-top-and-bottom/61684/1 "2022-03-07T05:22:53Z")

</div>

I wish to plot a series with _ **historic** _ data, but it should be zoomed in to the _ **last** _ year when it starts out. My problem is that when I zoom in to the range of the last year using range for xaxis and yaxis, the line graph _ **touches** _ the xaxis on the top and the bottom. How can I program it so that it zooms in without touching the axes. One way would be to increase the range for the yaxis with an extra 6 percent on the top and the bottom like R does for base R graphics. I was wondering if there is a feature in plotly which does this automatically. I would love to hear from the community here.

Here is a reprex:-

```auto
library(zoo)
library(quantmod)
library(plotly)

myplotly <- function(x,n){
    mydf <- data.frame(data.frame(x,row.names=NULL), "Date"=index(x))
    colnames(mydf)[1] = "Data"
    plot_ly(mydf,type="scatter",mode="lines") %>%
        add_trace(x=~Date, y =~Data,hovertemplate = '%{x:%A} %{y:.2f}<extra></extra>') %>%
        layout(title=n,
               xaxis=list(title="",mirror=TRUE,showline=TRUE,linewidth=2, range=c(Sys.Date()-365,Sys.Date())),
               yaxis=list(title="",showline=TRUE,linewidth=2,mirror=TRUE, range = c(min(window(x,start = Sys.Date()-365)),max(window(x,start = Sys.Date()-365, end = Sys.Date())))),
               showlegend=FALSE)
        
}

getSymbols("GOOG")
myplotly(GOOG[,4],"Time Series")

```

As you will see in the above graph the graph starts out touching the xaxis on the top and the bottom.
