title: Plot long time-series data using ggplot
body: <p>I have time-series data of four years. Now I want to plot the same data year-wise and do comparative analysis. The dummy data is as</p>
  
  <pre><code>library(xts)
  library(ggplot2)
  timeindex &lt;- seq(as.POSIXct('2016-01-01'),as.POSIXct('2016-12-31 23:59:59'), by = "1 mins")
  dataframe &lt;- data.frame(year1=rnorm(length(timeindex),100,10),year2=rnorm(length(timeindex),150,7),
                          year3=rnorm(length(timeindex),200,3),
                          year4=rnorm(length(timeindex),350,4))
  xts_df &lt;- xts(dataframe,timeindex) 
  </code></pre>
  
  <p>Now, when I use ggplot it takes too long to plot all the series using following lines</p>
  
  <pre><code>visualize_dataframe_all_columns(xts_df)
  </code></pre>
  
  <p>The above function is defined as:</p>
  
  <pre><code>visualize_dataframe_all_columns &lt;- function(xts_data) {
    library(RColorBrewer)# to increase no. of colors
    library(plotly)
    dframe &lt;- data.frame(timeindex=index(xts_data),coredata(xts_data))
    df_long &lt;- reshape2::melt(dframe,id.vars = "timeindex")
    colourCount = length(unique(df_long$variable))
    getPalette = colorRampPalette(brewer.pal(8, "Dark2"))(colourCount) # brewer.pal(8, "Dark2") or brewer.pal(9, "Set1")
    g &lt;- ggplot(df_long,aes(timeindex,value,col=variable,group=variable))
    g &lt;- g + geom_line() + scale_colour_manual(values=getPalette)
    ggplotly(g)
  }
  </code></pre>
  
  <p>Problems with above approach are:</p>
  
  <ol>
  <li>It takes long time to plot. Can I reduce the plot time?</li>
  <li>It is very diffcult to zoom into the plot using <code>plotly</code>. Is there any other better way</li>
  </ol>
  
  <p>Are there any better approaches to visualize this data? </p>