r prediction through r and shiny

 timeseies<-ts(dt$Record,start = c(2009,1),frequency = 12)
  timeseies
  arimodel<-auto.arima(timeseies) 
  arimodel
  predictionf<-forecast(arimodel,h=24,level=c(80,95))
  
  p <- plot_ly() %>%
    add_trace(x = ~time(timeseies), y = ~timeseies, type = 'scatter', mode = 'markers',
              line = list(color='rgb(0,100,80)'),
              name = 'available_records') %>%
    # add_lines(x = time(timeseies), y = timeseies,
    #           color = I("blue"), name = "observed") %>%
     add_ribbons(x = time(predictionf$mean), ymin = predictionf$lower[, 2], ymax = predictionf$upper[, 2],
                color = I('rgba(67,67,67,1)'), name = "95% confidence") %>%
    add_ribbons(x = time(predictionf$mean), ymin = predictionf$lower[, 1], ymax = predictionf$upper[, 1],
                color = I('rgba(49,130,189, 1)'), name = "80% confidence") %>%
    add_lines(x = time(predictionf$mean), y = predictionf$mean, color = I("blue"), name = "prediction",hoveron = "points") %>% 
    
    layout(title = "forcasting for delivery records through arima model",
           paper_bgcolor='rgb(255,255,255)', plot_bgcolor='rgb(229,229,229)',
           xaxis = list(title = "delivery-years",
                        gridcolor = 'rgb(255,255,255)',
                        showgrid = TRUE,
                        showline = FALSE,
                        showticklabels = TRUE,
                        tickcolor = 'rgb(127,127,127)',
                        ticks = 'outside',
                        zeroline = FALSE),
           yaxis = list(title = "delivery records (thousands)",
                        gridcolor = 'rgb(255,255,255)',
                        showgrid = TRUE,
                        showline = FALSE,
                        showticklabels = TRUE,
                        tickcolor = 'rgb(127,127,127)',
                        ticks = 'outside',
                        zeroline = FALSE))
    p
  
})

how to make this model better in this scenario...

Ok this is plotly. The trick with plotly is to find the correct variable to set.

The pop-up text is called hovertext. Plotly aesthetics are listed here:

https://plot.ly/r/reference/

..., hovertext=myhovertextvector, hoverinfo="text, ...".

For axis labels, the best idea is to use manual axis labels. That's also listed on the same web page;

xaxis=list(..., tickmode="array", tickvals=mytickvalvector, ticktext=myticktextvector, ...)

I think that's right.

I don't use ~ with ploty ; this tells plotly to use a column of the dataframe, but I think it's easier to just supply the vector directly.

1 Like

thanks for your time

there is one problem though ,the values of years are dynamic ,i can not create static vector and something like that for this scenario ,in that case what would be best way to serve this specific purpose,i mean value for h varies from time to time (years to be predicted) and is there any solution for month after year,as depicted in "2.png" scenario given above

The way I do it to first create the plotly using renderPlotly, then create a proxy using plotlyProxy, and then use the proxy to update the plotly using plotlyProxyInvoke. I currently use the approach below, which is closer to the javascript format, which allows create the argument lists outside the plotly call. It's a pity the R interface to plotly changes the argument structure a bit.

3 Likes

thanks for your help, I got an idea from your code, appreciate your concern

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.