0

enter image description here

I have a set of data with time in minutes. I want to convert time(min) variables into time series to plot them as time series with dygraph. How can I can convert Time(min) variable as a time series. It increments by 0.01667 (minute) in each step.

alistaire
  • 42,459
  • 4
  • 77
  • 117
erlika
  • 9
  • 1
  • 2
    Please provide your data-set in a [reproducible form](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and not as a screenshot. Also, please provide what code you have attempted and what is your expected result you are trying to get. – Adam Quek Apr 19 '17 at 05:15

1 Answers1

0

I don´t use dygraphs for R. I only can help you with a solution for dygraphs for javascript. Maybe this could help you. As you are using fractions or minutes, corresponding to steps of 1 second, I would show the time as seconds. To do that, I have used the xValueParser and the valueFormatter. Below I leave you my code

https://jsfiddle.net/Lucidio/s4fbwmvj/

 var data = "date,value1,value2\n" +
   "0.0167,1,4\n" +
   "0.0333,20,8\n" +
   "0.0500,10,6\n" +
   "0.0667,4,7\n" +
   "0.08333,5,9";
 
  q = new Dygraph(
   document.getElementById("qdiv"),
   data, {
     title: 'Parsing minutes',
     axes: {
       x: {
         valueFormatter: function(seconds){
            var formattedDate = formatDate(seconds);
            return formattedDate;
          }
       }
     },
     xValueParser: function(x) {
        var timeInSeconds = 60*x;
        return timeInSeconds;
     },
     legend: 'always',
   });
     
   function formatDate(seconds) {
      var roundSeconds = "second " + Math.round(seconds);
        return roundSeconds;
      }
<link href="https://cdnjs.cloudflare.com/ajax/libs/dygraph/2.0.0/dygraph.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dygraph/2.0.0/dygraph.js"></script>
<title>Parsing time</title>

<body>
  <div id="root">
    <div id="qdiv"></div>
   </div>
Lucidio Vacas
  • 700
  • 2
  • 8
  • 22