I have a data in R like the following:
bag_id location_type event_ts
1 155 transfer 2012-01-02 15:57:54
2 155 sorter 2012-01-02 17:06:05
3 305 arrival 2012-01-01 07:20:16
4 692 arrival 2012-03-29 09:47:52
10 748 transfer 2012-01-08 17:26:02
11 748 sorter 2012-01-08 17:30:02
12 993 arrival 2012-01-23 08:58:54
13 1019 arrival 2012-01-09 07:17:02
14 1019 sorter 2012-01-09 07:33:15
15 1154 transfer 2012-01-12 21:07:50
where class(event_ts) is "POSIXct".
I wanted to find the density of bags at each location in different times. So, I used the function density like the following:
adj<-.00001
dSorter<-density(as.numeric(Data$event_ts[which(Data$location_type=="sorter")]),n=length(Data$event_ts[which(Data$location_type=="sorter")]),adjust = adj)
StartTime<-as.POSIXct(strptime("2012-06-01", "%Y-%m-%d"), tz="UTC") # want to zoom & see part of data
EndTime<-as.POSIXct(strptime("2012-06-3", "%Y-%m-%d"), tz="UTC")
Range<-range(as.numeric(c(StartTime,EndTime)))
lablist.x<-substr(seq(StartTime,EndTime,by="hour"),start=6, stop=13) # want to have time labels for my plot
plot(dSorter, main="Sorter",xlim=Range, xaxt = "n")
axis(1, at=as.numeric(seq(StartTime,EndTime,by="hour")), labels =F)
text(1:49,par("usr")[3] - 0.25, labels=lablist.x,srt = 45,adj=1, , xpd = TRUE) #want to rotate the labels
The last comment does not work and I do not know how should I recognize the "x" values at function "text".
Thank you in advance for any kind of comments and guidance.
Best, Shima.
The problem was solved, I found the coordinates that I have to use in function "text" with the command: par("usr") and changed the last line of my code as the following:
text(c(as.numeric(seq(StartTime,EndTime,by="hour"))),par("usr")[3]-(par("usr")[4]-par("usr")[3])/20, labels=lablist.x,srt = 45,adj=1, xpd = TRUE)