Line graph not displayed with plotly in R











up vote
0
down vote

favorite












My final aim is to create 2 time series line graphs on the same plot, with the one being static and the other being animated (the former refers to the actual data and the latter on my model's fitted values). I am trying to accomplish that with plotly, however I am completely new and have crossed difficulties.



In order to get familiar with plotly first before attempting the above I initially tried to create just one animated graph on a plot. However I cannot even make that ostensibly simple script work. When running the below no graph is displayed on my plot area, like there are no data. My script is created based on following link: https://plot.ly/r/cumulative-animations/



plot_ly(data
, x=~data$RequCreatedFull_Date
, y=~data$fitted_TotalRequ_Qnt_pm
, name="Fitted"
, type='scatter'
, mode = "lines"
, line = list(color = "rgb(255,128,0)")
, frame = ~data$RequCreatedFull_Date
, line = list(simplyfy = F)) %>%
layout(title="name"
, xaxis = list(range =
c(as.numeric(min(data$RequCreatedFull_Date))*1000
,as.numeric(max(data$RequCreatedFull_Date))*1000)
, type = "date"
, title = "Requisition Date"
, zeroline = F)
, yaxis = list(title="Total Requisition Qnts"
, range = c(1000,30000)
, zeroline = F)) %>%
animation_opts(frame = 100,
transition = 0,
redraw=FALSE) %>%
animation_button(x = 1, xanchor = "right", y = 0, yanchor = "bottom")


data is a 53 obs, 4 variables (dates, actuals, fits, index) data frame.



When 'Play' button for animation is clicked and while the animation's frames proceed, when hovering on the plot area the data points' tooltips are displayed for a moment, however no graph is displayed.



Thank you in advance for all your assistance, hope I provided you with sufficient info.










share|improve this question






















  • Could you share just a sample of your data ? And do you get any error messages ?
    – RK1
    Sep 12 at 12:22










  • I did not get any error message, the plot area was displayed correctly and the animation slider was running normally. In any case, I found my error (check answer below). Thanks though
    – Paris
    Sep 12 at 16:01












  • fantastic! would be helpful if you show the code changes you made in your answer below to get it working
    – RK1
    Sep 12 at 16:31










  • Thanks for the feedback @RK1. Please check my edited final answer.
    – Paris
    Sep 13 at 7:37















up vote
0
down vote

favorite












My final aim is to create 2 time series line graphs on the same plot, with the one being static and the other being animated (the former refers to the actual data and the latter on my model's fitted values). I am trying to accomplish that with plotly, however I am completely new and have crossed difficulties.



In order to get familiar with plotly first before attempting the above I initially tried to create just one animated graph on a plot. However I cannot even make that ostensibly simple script work. When running the below no graph is displayed on my plot area, like there are no data. My script is created based on following link: https://plot.ly/r/cumulative-animations/



plot_ly(data
, x=~data$RequCreatedFull_Date
, y=~data$fitted_TotalRequ_Qnt_pm
, name="Fitted"
, type='scatter'
, mode = "lines"
, line = list(color = "rgb(255,128,0)")
, frame = ~data$RequCreatedFull_Date
, line = list(simplyfy = F)) %>%
layout(title="name"
, xaxis = list(range =
c(as.numeric(min(data$RequCreatedFull_Date))*1000
,as.numeric(max(data$RequCreatedFull_Date))*1000)
, type = "date"
, title = "Requisition Date"
, zeroline = F)
, yaxis = list(title="Total Requisition Qnts"
, range = c(1000,30000)
, zeroline = F)) %>%
animation_opts(frame = 100,
transition = 0,
redraw=FALSE) %>%
animation_button(x = 1, xanchor = "right", y = 0, yanchor = "bottom")


data is a 53 obs, 4 variables (dates, actuals, fits, index) data frame.



When 'Play' button for animation is clicked and while the animation's frames proceed, when hovering on the plot area the data points' tooltips are displayed for a moment, however no graph is displayed.



Thank you in advance for all your assistance, hope I provided you with sufficient info.










share|improve this question






















  • Could you share just a sample of your data ? And do you get any error messages ?
    – RK1
    Sep 12 at 12:22










  • I did not get any error message, the plot area was displayed correctly and the animation slider was running normally. In any case, I found my error (check answer below). Thanks though
    – Paris
    Sep 12 at 16:01












  • fantastic! would be helpful if you show the code changes you made in your answer below to get it working
    – RK1
    Sep 12 at 16:31










  • Thanks for the feedback @RK1. Please check my edited final answer.
    – Paris
    Sep 13 at 7:37













up vote
0
down vote

favorite









up vote
0
down vote

favorite











My final aim is to create 2 time series line graphs on the same plot, with the one being static and the other being animated (the former refers to the actual data and the latter on my model's fitted values). I am trying to accomplish that with plotly, however I am completely new and have crossed difficulties.



In order to get familiar with plotly first before attempting the above I initially tried to create just one animated graph on a plot. However I cannot even make that ostensibly simple script work. When running the below no graph is displayed on my plot area, like there are no data. My script is created based on following link: https://plot.ly/r/cumulative-animations/



plot_ly(data
, x=~data$RequCreatedFull_Date
, y=~data$fitted_TotalRequ_Qnt_pm
, name="Fitted"
, type='scatter'
, mode = "lines"
, line = list(color = "rgb(255,128,0)")
, frame = ~data$RequCreatedFull_Date
, line = list(simplyfy = F)) %>%
layout(title="name"
, xaxis = list(range =
c(as.numeric(min(data$RequCreatedFull_Date))*1000
,as.numeric(max(data$RequCreatedFull_Date))*1000)
, type = "date"
, title = "Requisition Date"
, zeroline = F)
, yaxis = list(title="Total Requisition Qnts"
, range = c(1000,30000)
, zeroline = F)) %>%
animation_opts(frame = 100,
transition = 0,
redraw=FALSE) %>%
animation_button(x = 1, xanchor = "right", y = 0, yanchor = "bottom")


data is a 53 obs, 4 variables (dates, actuals, fits, index) data frame.



When 'Play' button for animation is clicked and while the animation's frames proceed, when hovering on the plot area the data points' tooltips are displayed for a moment, however no graph is displayed.



Thank you in advance for all your assistance, hope I provided you with sufficient info.










share|improve this question













My final aim is to create 2 time series line graphs on the same plot, with the one being static and the other being animated (the former refers to the actual data and the latter on my model's fitted values). I am trying to accomplish that with plotly, however I am completely new and have crossed difficulties.



In order to get familiar with plotly first before attempting the above I initially tried to create just one animated graph on a plot. However I cannot even make that ostensibly simple script work. When running the below no graph is displayed on my plot area, like there are no data. My script is created based on following link: https://plot.ly/r/cumulative-animations/



plot_ly(data
, x=~data$RequCreatedFull_Date
, y=~data$fitted_TotalRequ_Qnt_pm
, name="Fitted"
, type='scatter'
, mode = "lines"
, line = list(color = "rgb(255,128,0)")
, frame = ~data$RequCreatedFull_Date
, line = list(simplyfy = F)) %>%
layout(title="name"
, xaxis = list(range =
c(as.numeric(min(data$RequCreatedFull_Date))*1000
,as.numeric(max(data$RequCreatedFull_Date))*1000)
, type = "date"
, title = "Requisition Date"
, zeroline = F)
, yaxis = list(title="Total Requisition Qnts"
, range = c(1000,30000)
, zeroline = F)) %>%
animation_opts(frame = 100,
transition = 0,
redraw=FALSE) %>%
animation_button(x = 1, xanchor = "right", y = 0, yanchor = "bottom")


data is a 53 obs, 4 variables (dates, actuals, fits, index) data frame.



When 'Play' button for animation is clicked and while the animation's frames proceed, when hovering on the plot area the data points' tooltips are displayed for a moment, however no graph is displayed.



Thank you in advance for all your assistance, hope I provided you with sufficient info.







r plotly r-plotly timeserieschart






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 12 at 10:43









Paris

112




112












  • Could you share just a sample of your data ? And do you get any error messages ?
    – RK1
    Sep 12 at 12:22










  • I did not get any error message, the plot area was displayed correctly and the animation slider was running normally. In any case, I found my error (check answer below). Thanks though
    – Paris
    Sep 12 at 16:01












  • fantastic! would be helpful if you show the code changes you made in your answer below to get it working
    – RK1
    Sep 12 at 16:31










  • Thanks for the feedback @RK1. Please check my edited final answer.
    – Paris
    Sep 13 at 7:37


















  • Could you share just a sample of your data ? And do you get any error messages ?
    – RK1
    Sep 12 at 12:22










  • I did not get any error message, the plot area was displayed correctly and the animation slider was running normally. In any case, I found my error (check answer below). Thanks though
    – Paris
    Sep 12 at 16:01












  • fantastic! would be helpful if you show the code changes you made in your answer below to get it working
    – RK1
    Sep 12 at 16:31










  • Thanks for the feedback @RK1. Please check my edited final answer.
    – Paris
    Sep 13 at 7:37
















Could you share just a sample of your data ? And do you get any error messages ?
– RK1
Sep 12 at 12:22




Could you share just a sample of your data ? And do you get any error messages ?
– RK1
Sep 12 at 12:22












I did not get any error message, the plot area was displayed correctly and the animation slider was running normally. In any case, I found my error (check answer below). Thanks though
– Paris
Sep 12 at 16:01






I did not get any error message, the plot area was displayed correctly and the animation slider was running normally. In any case, I found my error (check answer below). Thanks though
– Paris
Sep 12 at 16:01














fantastic! would be helpful if you show the code changes you made in your answer below to get it working
– RK1
Sep 12 at 16:31




fantastic! would be helpful if you show the code changes you made in your answer below to get it working
– RK1
Sep 12 at 16:31












Thanks for the feedback @RK1. Please check my edited final answer.
– Paris
Sep 13 at 7:37




Thanks for the feedback @RK1. Please check my edited final answer.
– Paris
Sep 13 at 7:37












2 Answers
2






active

oldest

votes

















up vote
1
down vote













I mistakenly took part of the script the below link for the animated plotting (https://plot.ly/r/cumulative-animations/). The problem is that I did not modify the to-be-framed variable (variable to be used in frame parameter of plot_ly function) before using it.



Therefore, in order for the plot to work properly I should: 1. define accumulate_by function, 2. use it with the to-be-framed variable as input, 3. the output column produced from step 2 will be the value for the frame parameter of 'plot_ly' function.



Initial working data frame is data2, with columns RequCreatedFull-Date(as POSIXct), Requs_Qnt_pm(as num), Type(as Factor), date(as num) where
date=(year(RequCreatedFull_Date)+(month(RequCreatedFull_Date)-1)/12).



Please refer to working script below:



library(plotly)
library(dplyr)
library(lubridate)

#step 1: function definition
accumulate_by <- function(dat, var) {
var <- lazyeval::f_eval(var, dat)
lvls <- plotly:::getLevels(var)
dats <- lapply(seq_along(lvls), function(x) {
cbind(dat[var %in% lvls[seq(1, x)], ], frame = lvls[[x]])
})
dplyr::bind_rows(dats)
}

#step 2: creation of to-be-used for framing variable
data2mod <- data2 %>%
accumulate_by(~date)


#graph creation
my_graph<-data2mod %>%
plot_ly(
x = ~date,
y = ~Requs_Qnt_pm,
split = ~Type,
frame = ~frame, #step 3, to be frame variable insertion
type = 'scatter',
mode = 'lines',
line = list(simplyfy = F)
) %>%
layout(
xaxis = list(
title = "x axis title",
zeroline = F
),
yaxis = list(
title = "y axis title",
zeroline = F
)
) %>%
animation_opts(
frame = 100,
transition = 0,
redraw = FALSE
) %>%
animation_slider(
hide = T
) %>%
animation_button(
x = 1, xanchor = "right", y = 0, yanchor = "bottom"
)





share|improve this answer






























    up vote
    0
    down vote













    In xaxis and in yaxis showline=TRUE






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52293263%2fline-graph-not-displayed-with-plotly-in-r%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote













      I mistakenly took part of the script the below link for the animated plotting (https://plot.ly/r/cumulative-animations/). The problem is that I did not modify the to-be-framed variable (variable to be used in frame parameter of plot_ly function) before using it.



      Therefore, in order for the plot to work properly I should: 1. define accumulate_by function, 2. use it with the to-be-framed variable as input, 3. the output column produced from step 2 will be the value for the frame parameter of 'plot_ly' function.



      Initial working data frame is data2, with columns RequCreatedFull-Date(as POSIXct), Requs_Qnt_pm(as num), Type(as Factor), date(as num) where
      date=(year(RequCreatedFull_Date)+(month(RequCreatedFull_Date)-1)/12).



      Please refer to working script below:



      library(plotly)
      library(dplyr)
      library(lubridate)

      #step 1: function definition
      accumulate_by <- function(dat, var) {
      var <- lazyeval::f_eval(var, dat)
      lvls <- plotly:::getLevels(var)
      dats <- lapply(seq_along(lvls), function(x) {
      cbind(dat[var %in% lvls[seq(1, x)], ], frame = lvls[[x]])
      })
      dplyr::bind_rows(dats)
      }

      #step 2: creation of to-be-used for framing variable
      data2mod <- data2 %>%
      accumulate_by(~date)


      #graph creation
      my_graph<-data2mod %>%
      plot_ly(
      x = ~date,
      y = ~Requs_Qnt_pm,
      split = ~Type,
      frame = ~frame, #step 3, to be frame variable insertion
      type = 'scatter',
      mode = 'lines',
      line = list(simplyfy = F)
      ) %>%
      layout(
      xaxis = list(
      title = "x axis title",
      zeroline = F
      ),
      yaxis = list(
      title = "y axis title",
      zeroline = F
      )
      ) %>%
      animation_opts(
      frame = 100,
      transition = 0,
      redraw = FALSE
      ) %>%
      animation_slider(
      hide = T
      ) %>%
      animation_button(
      x = 1, xanchor = "right", y = 0, yanchor = "bottom"
      )





      share|improve this answer



























        up vote
        1
        down vote













        I mistakenly took part of the script the below link for the animated plotting (https://plot.ly/r/cumulative-animations/). The problem is that I did not modify the to-be-framed variable (variable to be used in frame parameter of plot_ly function) before using it.



        Therefore, in order for the plot to work properly I should: 1. define accumulate_by function, 2. use it with the to-be-framed variable as input, 3. the output column produced from step 2 will be the value for the frame parameter of 'plot_ly' function.



        Initial working data frame is data2, with columns RequCreatedFull-Date(as POSIXct), Requs_Qnt_pm(as num), Type(as Factor), date(as num) where
        date=(year(RequCreatedFull_Date)+(month(RequCreatedFull_Date)-1)/12).



        Please refer to working script below:



        library(plotly)
        library(dplyr)
        library(lubridate)

        #step 1: function definition
        accumulate_by <- function(dat, var) {
        var <- lazyeval::f_eval(var, dat)
        lvls <- plotly:::getLevels(var)
        dats <- lapply(seq_along(lvls), function(x) {
        cbind(dat[var %in% lvls[seq(1, x)], ], frame = lvls[[x]])
        })
        dplyr::bind_rows(dats)
        }

        #step 2: creation of to-be-used for framing variable
        data2mod <- data2 %>%
        accumulate_by(~date)


        #graph creation
        my_graph<-data2mod %>%
        plot_ly(
        x = ~date,
        y = ~Requs_Qnt_pm,
        split = ~Type,
        frame = ~frame, #step 3, to be frame variable insertion
        type = 'scatter',
        mode = 'lines',
        line = list(simplyfy = F)
        ) %>%
        layout(
        xaxis = list(
        title = "x axis title",
        zeroline = F
        ),
        yaxis = list(
        title = "y axis title",
        zeroline = F
        )
        ) %>%
        animation_opts(
        frame = 100,
        transition = 0,
        redraw = FALSE
        ) %>%
        animation_slider(
        hide = T
        ) %>%
        animation_button(
        x = 1, xanchor = "right", y = 0, yanchor = "bottom"
        )





        share|improve this answer

























          up vote
          1
          down vote










          up vote
          1
          down vote









          I mistakenly took part of the script the below link for the animated plotting (https://plot.ly/r/cumulative-animations/). The problem is that I did not modify the to-be-framed variable (variable to be used in frame parameter of plot_ly function) before using it.



          Therefore, in order for the plot to work properly I should: 1. define accumulate_by function, 2. use it with the to-be-framed variable as input, 3. the output column produced from step 2 will be the value for the frame parameter of 'plot_ly' function.



          Initial working data frame is data2, with columns RequCreatedFull-Date(as POSIXct), Requs_Qnt_pm(as num), Type(as Factor), date(as num) where
          date=(year(RequCreatedFull_Date)+(month(RequCreatedFull_Date)-1)/12).



          Please refer to working script below:



          library(plotly)
          library(dplyr)
          library(lubridate)

          #step 1: function definition
          accumulate_by <- function(dat, var) {
          var <- lazyeval::f_eval(var, dat)
          lvls <- plotly:::getLevels(var)
          dats <- lapply(seq_along(lvls), function(x) {
          cbind(dat[var %in% lvls[seq(1, x)], ], frame = lvls[[x]])
          })
          dplyr::bind_rows(dats)
          }

          #step 2: creation of to-be-used for framing variable
          data2mod <- data2 %>%
          accumulate_by(~date)


          #graph creation
          my_graph<-data2mod %>%
          plot_ly(
          x = ~date,
          y = ~Requs_Qnt_pm,
          split = ~Type,
          frame = ~frame, #step 3, to be frame variable insertion
          type = 'scatter',
          mode = 'lines',
          line = list(simplyfy = F)
          ) %>%
          layout(
          xaxis = list(
          title = "x axis title",
          zeroline = F
          ),
          yaxis = list(
          title = "y axis title",
          zeroline = F
          )
          ) %>%
          animation_opts(
          frame = 100,
          transition = 0,
          redraw = FALSE
          ) %>%
          animation_slider(
          hide = T
          ) %>%
          animation_button(
          x = 1, xanchor = "right", y = 0, yanchor = "bottom"
          )





          share|improve this answer














          I mistakenly took part of the script the below link for the animated plotting (https://plot.ly/r/cumulative-animations/). The problem is that I did not modify the to-be-framed variable (variable to be used in frame parameter of plot_ly function) before using it.



          Therefore, in order for the plot to work properly I should: 1. define accumulate_by function, 2. use it with the to-be-framed variable as input, 3. the output column produced from step 2 will be the value for the frame parameter of 'plot_ly' function.



          Initial working data frame is data2, with columns RequCreatedFull-Date(as POSIXct), Requs_Qnt_pm(as num), Type(as Factor), date(as num) where
          date=(year(RequCreatedFull_Date)+(month(RequCreatedFull_Date)-1)/12).



          Please refer to working script below:



          library(plotly)
          library(dplyr)
          library(lubridate)

          #step 1: function definition
          accumulate_by <- function(dat, var) {
          var <- lazyeval::f_eval(var, dat)
          lvls <- plotly:::getLevels(var)
          dats <- lapply(seq_along(lvls), function(x) {
          cbind(dat[var %in% lvls[seq(1, x)], ], frame = lvls[[x]])
          })
          dplyr::bind_rows(dats)
          }

          #step 2: creation of to-be-used for framing variable
          data2mod <- data2 %>%
          accumulate_by(~date)


          #graph creation
          my_graph<-data2mod %>%
          plot_ly(
          x = ~date,
          y = ~Requs_Qnt_pm,
          split = ~Type,
          frame = ~frame, #step 3, to be frame variable insertion
          type = 'scatter',
          mode = 'lines',
          line = list(simplyfy = F)
          ) %>%
          layout(
          xaxis = list(
          title = "x axis title",
          zeroline = F
          ),
          yaxis = list(
          title = "y axis title",
          zeroline = F
          )
          ) %>%
          animation_opts(
          frame = 100,
          transition = 0,
          redraw = FALSE
          ) %>%
          animation_slider(
          hide = T
          ) %>%
          animation_button(
          x = 1, xanchor = "right", y = 0, yanchor = "bottom"
          )






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Sep 13 at 7:41

























          answered Sep 12 at 15:58









          Paris

          112




          112
























              up vote
              0
              down vote













              In xaxis and in yaxis showline=TRUE






              share|improve this answer

























                up vote
                0
                down vote













                In xaxis and in yaxis showline=TRUE






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  In xaxis and in yaxis showline=TRUE






                  share|improve this answer












                  In xaxis and in yaxis showline=TRUE







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  Matt Dnv

                  235




                  235






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52293263%2fline-graph-not-displayed-with-plotly-in-r%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      'app-layout' is not a known element: how to share Component with different Modules

                      android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                      SQL update select statement