Graph time series in seconds with dygraph - r

I get data from a device recording roughly every 8 to 10 ms. Here is how the raw data looks like (with Time in seconds):
> data
Time Raw
1 0.004061294 0.7384716
2 0.012264294 1.9172491
3 0.020467294 2.2663045
4 0.028670294 1.1509293
5 0.037858294 1.6099277
6 0.048030294 0.7834101
...
The file is very long, and I would like to inspect it first with a scrollable x-axis. Therefore, I treated this data as a time series and used the dygraphs package to visualize it.
data_ts <- as.ts(data$Raw)
dygraph(ts_data, main="Raw signal") %>%
dyRangeSelector()
The result is great, but I would like to be able to see the values of the x-axis in seconds (or miliseconds). So far, nothing is displayed and I can't wrap my head around the problem. I guess it may have something to do with the fact that I haven't specified the unit of the time series. Or that my data does not fit the requirement of a time series, since the time intervals are slightly irregular.
Thanks for your help!
Any other solutions that would allow to scroll the x-axis are also welcome.

Related

I have data grouped by UK financial year but when I try to use an R time series function with a frequency of 4 and then plot it, I get a strange chart

I have a table as follows:
Data table
I am trying to do a time series analysis in R. After importing the data set into R, when I use the following
time_series <- ts(ts_data$Recruitment, start= min(ts_data$Quarter),end=max(ts_data$Quarter),frequency=4)
and then use plot() to chart it, I get a chart with peaks in the wrong places. However when I set a frequency of 1 things look more normal. My question is, given that I'm dealing with quarterly data, shouldn't the frequency be 4?
I am very new to R and appreciate any advice. I saw the following example in a training course with a frequency of 4 that seemed to work, so I'm not sure why mine doesn't.
Quarterly data
Could it be to do with UK financial vs calendar year I wonder?
I tried using the frequency of 4 and then of 1. 1 seemed to produce the chart I was expecting, but 4 didn't. I'm not sure why as I'm dealing with quarterly data.
UPDATE
When I try with frequency 1 and then try to decompose the chart I get the following error:
"time series has no or less than 2 periods"
Can anybody help?

R timeseries jumps and plotting in dygraph

I have a time series of stock data of several days, and big jumps in between the days as the data in the closing time of the stock market is missing of course.
Picture shows what I mean:
Graph
The time series used to plot is an xts object, which looks like this:
xts object
The graph is plotted using the following function:
dygraph(stocks, main="Closing Stock Prices") %>%
dyAxis("y", label="Value") %>%
dySeries("..1",label="IBM") %>%
dyOptions(colors = c("blue"), connectSeparatedPoints=TRUE) %>%
dyRangeSelector()
Now what I really want is to "ignore" the value in between set dates and just plot the graph in one go without the gap between. Is this possible somehow?
I was thinking of just manipulating the time series and just consider as it single points as I don't necessarily need the time anyway but only the graph to be shown properly, but is this possible even as the xts object requires a time series object?!
Thanks in advance!!
Apparently there is no solution to hide it, other than going for NA values to hide the graph itself, but the gap which still exist.
I now went for a generated timestamp misused as index to simulate the effect of an ongoing graph.

Plot occurrences over time in R from a dataset of H:M:S timestamps

I'm trying to plot, essentially, a timeline. I have two lists of timestamps in %H:%M:%S format, and I want to show them as occurrences over an x-axis of continuous time from 0 to 8 minutes.
Everything I can find is either a specialized package for a timeline that bins data by year instead of showing it continuously scatterplot style, or it requires a y-axis. I'm not plotting a function, so I don't have a y-axis, just two lines made up of dots something like this: mock excel plot. I got this by putting in fake values for the missing axis. It's also vertical instead of horizontal, but that's easily fixed.
I'm trying to show all the times in those 8 minutes a person pronounced an S and all the times she deleted it so I can see if she starts deleting more as time goes on.
Edit: here's some of my data as requested.
s deleted s pronounced
0:02:32 0:00:49
0:04:01 0:00:50
0:04:02 0:00:51
0:04:10 0:00:56
0:04:11 0:00:58
0:04:44 0:00:59
0:05:59 0:01:09
0:06:03 0:01:10
0:06:31 0:01:12
0:06:33 0:05:59
0:06:40 0:06:00
0:06:06
0:06:06
0:06:32
0:06:43
0:06:44
0:06:47
0:06:51
0:06:52
0:07:10
0:07:14

Trying to plot graph in R using shiny , it is taking lot of time to load, data is somewhat 1 TB

I am trying to ploat a graph using ggplot. its asingle sales graph where x axis is year and y axis is sales in the particulat year using shiny framework in R. the input file contain dales detail for every day. Complete data size for approx 1 TB. Graph is getting plotted but it is taking lot of time approx 5 mins. please suggest any solution for the same.
thanks in advance
You can buy Solid-state drive to get faster loading of data if R supports.

Getting Date to Add Correctly

I have a 3000 x 1000 matrix time series database going back 14 years that is updated every three months. I am forecasting out 9 months using this data still keeping a 3200 x 1100 matrix (mind you these are rough numbers).
During the forecasting process I need the variables Year and Month to be calculated appropriately . I am trying to automate the process so I don't have to mess with the code any more; I can just run the code every three months and upload the projections into our database.
Below is the code I am using right now. As I said above I do not want to have to look at the data or the code just run the code every three months. Right now everything else is working as planed, but I still have to ensure the dates are appropriately annotated. The foo variables are changed for privacy purposes due to the nature of their names.
projection <- rbind(projection, data.frame(foo=forbar, bar=barfoo,
+ Year=2012, Month=1:9,
+ Foo=as.vector(fc$mean)))
I'm not sure exactly where the year/months are coming from, but if you want to refer to the current date for those numbers, here is an option (using the wonderful package, lubridate):
library(lubridate)
today = Sys.Date()
projection <- rbind(projection, data.frame(foo=foobar, bar=barfoo,
year = year(today),
month = sapply(1:9,function(x) month(today+months(x))),
Foo = as.vector(fc$mean)))
I hope this is what you're looking for.

Resources