I have a list of timestamps like shown at the end, and I am trying to make a histogram/frequency chart where the X-axis is the time and the y axis a count of the frequency. I tried doing something like this:
set term dumb
set xdata
set timefmt '%Y-%m-%dT%H:%M:%SZ'
set xrange ["16/04/2018":"14/04/2018"]
plot 'dat'
and in the data file
2018-04-16T14:54:38Z
2018-04-16T13:50:07Z
2018-04-16T12:30:45Z
2018-04-16T11:45:16Z
2018-04-16T11:44:11Z
2018-04-16T10:19:19Z
2018-04-16T10:13:25Z
2018-04-16T00:17:33Z
2018-04-15T23:10:15Z
2018-04-14T22:27:34Z
2018-04-14T23:11:29Z
2018-04-14T22:45:08Z
Result
As you can see the x axis does not represent the time.
EDIT:
With Christoph's fixed code, the result is a plot of the timestamp and row the number.
To better explain the problem I have:
I want to plot the time on the x-axis and I want to plot the number of occurrences of the timestamp on the y-axis and where the timestamps are binned to some value in hours and possibly instead of just drawing bars it would interpolate lines between the peaks of the bars.
I asked for you actual question, because the code you posted doesn't create any plot. Let's see:
If I execute only the code you posted, I get the error all points y value undefined!.
In plot time data on the x axis, you need set xdata time.
Having set that you would get as next error Need full using spec for x time data. Indeed, you must have a using when handling time data, something like
plot 'dat' using 1:0
Then, you would again get the error all points y value undefined!. This time, because the time strings given in set xrange must match those specified with set timefmt.
So, a working version of your code could be:
reset
set xdata time
set timefmt '%Y-%m-%dT%H:%M:%SZ'
set xrange ["2018-04-16":"2018-04-14"]
plot 'dat' using 1:0
This plots time on the xaxis, and the row number on the y-axis.
Related
I have a dataset like revenue and date.
I used arima to plot the data.
ts_data = ts(dataset$Revenue,frequency = 7)
arima.ts = auto.arima(ts_data)
pred = forecast(arima.ts,h=30)
plot(pred,xaxt="n")
When I plot the data, it produces plot like below.
My expectations are below,
I need to display values in Million for predicted values like 13.1M.
I need to show x-axis as date instead of data points numbers.
I tried several links but couldn't crack it. Below are the experiments I made,
Tried with start date and end date in ts_data that also doesnt work.My start date is "2019-09-27" and end date is "2020-07-02"
tried wit axis_date in plot function that also doesnt work.
Please help me to crack the same.
Thanks a lot.
You can specify axis tick values and labels with axis()
plot(pred,xaxt="n", yaxt="n") # deactivate x and y axis
yl<-seq(-5000000,15000000,by=5000000) # position of y-axis ticks
axis(2, at=yl, label=paste(yl/1000000, "M")) # 2 = left axis
You can specify the desired position of y axis ticks with at and the labels to be associated with label. In order to obtain the values like 10 M I have used the function paste to join the numbers with the letter M.
You could use the same method also for x-axis, even tough more efficient methods probably exist. Not having the specific data available I have used a generic spacing and labels only to give you the idea. Once you have set the desired position you can generate the sequence of dates associated with it (to generate a sequence of dates see https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/seq.Date)
axis(1, at=seq(1,40,by=1), label=seq(as.Date("2019-09-27"),as.Date("2020-07-02"),by="week")) # 1 = below axis
You can also change the format of the dates displayed with format() for example label=format(vector_of_date, "%Y-%b-%d") to have year-month(in letter)-day.
I have an excel scatter plot with 5 different data series on single chart. First 4 series are working well. When I want to add a new series with similar x-axis data (0.0, 0.4, 0.9 .. ) the plot is displayed with x-axis values as 1,2,3 but not as the data specified.
Changing the chart types did not help. Not sure how can I get the x-axis as data but not as sequential numbers. Any help is appreciated. Thanks.
Added the screenshot of chart and its xaxis data. The values are in number format only just as data for other series. Everytime I am adding a new series on to this, its starting with one number later.... (1,2,3...) next series x axis at (2,3,4....) but not with real x values as selected.
Solved it my slef... The problem is X-axis range is for 18 cells and all the cells had formula with IF condition... When I removed the IF condition, x-axis worked well as numbers
The IF condition I used was "=IF(A10<>"",B10=A10-A4,""), for some reason excel chart considered this as some text and populated the x axis as 1,2,3 but not as the values specified.
I have an xts series that I'm trying to plot. This series contains of intra-day date for a month with gaps in the data on the weekend. I use xyplot (lattice) in R to plot the time series and am very pleased with the results.
Unfortunately the plots keep the weekend gaps. I'd like to ignore the weekend gaps and make my timeseries plot continuous and would appreciate if someone pointed me in the right direction.
The current command is :
xyplot(close~MyTime, type='l', col='black',ylab='',xlab='', main='Test')
I tried JohnPaul's method and it 'nearly' works. The labels while present, don't render correctly. The last label only goes up to the 3rd of January, while the actual data extends all the way up to February. The command used was:
PlotOrd<-order(Mytime)
xyplot(close~PlotOrd, type='l', col='black',ylab='',xlab='', main='Close',scales=list( x=list( labels=MyTime)) )
If I understand this correctly, what you wish to do is have the weekends not appear in the plot at all. One way to do this is to make another vector which is the order in which you want close plotted - a vector that does not include weekends. Assuming that weekends are not included in time this should work:
PlotOrd<-order(Mytime)
xyplot(close~PlotOrd, type='l', col='black',ylab='',xlab='', main='Test')
This will give you the correct plot, but your x axis tick labels will just be the number from PlotOrd. If you want to keep them as dates add a scales argument for the x axis, like so:
xyplot(close~PlotOrd, type='l', col='black',ylab='',xlab='', main='Test',
scales=list( x=list( labels=Mytime )) )
EDIT
One way to control the axis labels is to use the at argument as well. It is kind of clunky here and I wish I could come up with a more elegant idea, but this will work:
xyplot(close~PlotOrd, type='l', col='black',ylab='',xlab='', main='Test',
scales=list( x=list(at=c(50,100,150,200), labels=Mytime[c(50,100,150,200)] )) )
This will put ticks at observations 50,100,150 and 200, and will give corresponding values from MyTime as the label. The downside is you have to write in the ticks yourself. You could add some code to make a sequence of values. Say you want a label every 15 days. If you figure out how many measurements that corresponds to, you can make a sequence of numbers that far apart (call it MyTicks). Then feed to at=MyTicks and labels=MyTime[MyTicks]. Still it would be nicer to have lattice just pick the ticks for you...
I am plotting the frequency of the data sampling in an interval. The code is:
n=50 #number of intervals
plot "xxx.csv" u ($0):1 #To get the max and min value
max=GPVAL_Y_MAX
min=GPVAL_Y_MIN
width=(max-min)/n #interval width
#function used to map a value to the intervals
hist(x,width)=width*floor(x/width)
set ytic auto
set xtic auto
plot "xxx.csv" u (hist($1,width)):(1.0) smooth freq w histeps ls 1 title "xxx"
This works, but I would like to put two similar graph overlapped with different data. The problem is that the data are different so max, min and width are not the same. The data are separated files like yyy.csv and zzz.csv. How can I do this?
Do you have gnuplot >= 4.6? If so you can use the stats command to get statistics for those files easily, otherwise it would probably be a matter of doing what you did in your script (plot, then use GPVAL_Y_MIN, etc.) and create a set of variables for each data set.
(Posting my earlier comment as an answer.)
I have a time series of zoo and POSIXct class using second intervals. However, as is usually the case in financial time series, there are often long time gaps without information (ex. overnight). When using plot.zoo, the useful (populated) intervals appear scrunched relative to the unused intervals. Is there some way to simply omit time intervals in the plotting function of plot.zoo(). P.S. It's possible to just simply plot the continuous time series (plot(ts(obj)), but then the time information is lost on the x axis.
#AndresT Thanks for the idea, but the data is already filtered. It is the plot.zoo() function that appears to be padding unused sample intervals to keep the total x range
active. Pls see example below.
library(zoo)
st<-Sys.time()
t<-c(st, st+500, st+1000, st+1500, st+2000, st+90000, st+95000, st+100000)
rn<-runif(7)
zr<-zoo(rn, order.by=t)
plot.zoo(zr,type='o')
compare to the uniform spacing from plot(ts(data))
layout(1:2)
plot.zoo(zr, type='o')
plot(ts(zr),type='o')
So I would like to basically have the 2nd ts plot, but labeled with the corresponding x-axis labels from the 1st plot.zoo() function.
Try this:
library(quantmod)
chartSeries(zr)