Following data can be either a tibble
or data.table
:
datetime volume
<dttm> <dbl>
2020-08-25 09:30:00.000 0
2020-08-25 09:30:12.000 107
2020-08-25 09:30:50.000 221
2020-08-25 09:30:50.000 132
2020-08-25 09:30:50.000 148
2020-08-25 09:30:50.000 100
2020-08-25 09:30:50.000 100
2020-08-25 09:30:58.000 100
2020-08-25 09:31:56.000 157
2020-08-25 09:32:36.000 288
2020-08-25 09:32:36.000 100
2020-08-25 09:33:10.000 235
2020-08-25 09:33:23.000 182
2020-08-25 09:33:44.000 218
2020-08-25 09:33:44.000 179
2020-08-25 09:34:18.000 318
2020-08-25 09:34:27.000 101
2020-08-25 09:34:27.000 157
2020-08-25 09:34:27.000 200
2020-08-25 09:34:27.000 114
I have converted above data into a xts
object and wanted to call the plotting function from Rscript
, as a command line utility.
Here's how I transform my data into xts
:
data %>% as.xts() -> testdata1
Above line of code does not make a different time series than:
data %>% as.xts() -> testdata2
identical(testdata1, testdata2)
# output: TRUE
on SO there were 2 possible methods to go about this:
# first option
x11() # linux calls x11()
plot(x = data,
observation.based = TRUE,
major.ticks = "seconds",
main = "Test Plot")
prompt <- "press any key to close the plot"
capture <- tcltk::tk_messageBox(message = prompt)
# second option
png("test.png")
plot(x = data,
observation.based = TRUE,
major.ticks = "seconds",
main = "Test Plot")
dev.off()
browseURL("test.png)
Neither of above worked for xts
object plotting. it worked for plain data.frame
, data.table
and ggplot
.
Anyone has tried plotting xts
to the new device, from command line?