I'm missing something simple here so a pointer is needed. The base data is a data frame, col.riv. That was converted to a matrix: col.riv.mat <- data.matrix(col.riv) then to a timeSeries object: col.riv.ts <- ts(col.riv.mat)> class(col.riv.ts)[1] "mts" "ts" "matrix" I would like to plot (separately) time series for the 'disch' and 'tempMean' columns but have not had success in passing the correct syntax to the plot() function and having the x-axis labels as human-readable dates rather than the epoch time (which is what I assume is in the date class). I've extracted some rows from the base data frame with dput() for use in working out how to proceed: structure(list(date = structure(c(16071, 16072, 16073, 16074, 16075, 16076, 16077, 16078, 16079, 16080, 16081, 16082, 16083, 16084, 16085, 16086, 16087, 16088, 16089, 16090, 16091, 16092, 16093, 16094, 16095, 16096, 16097, 16098, 16099, 16100, 16101, 16102, 16103, 16104, 16105, 16106, 16107, 16108, 16109, 16110, 16111, 16112, 16113, 16114, 16115, 16116, 16117, 16118, 16119, 16120, 16121, 16122, 16123, 16124, 16125, 16126, 16127, 16128, 16129, 16130, 16131), class = "Date"), disch = c(119000L, 125000L, 129000L, 125000L, 122000L, 155000L, 157000L, 152000L, 156000L, 156000L, 106000L, 147000L, 123000L, 123000L, 128000L, 150000L, 135000L, 135000L, 134000L, 144000L, 154000L, 152000L, 139000L, 147000L, 135000L, 147000L, 131000L, 146000L, 116000L, 111000L, 124000L, 124000L, 120000L, 119000L, 124000L, 132000L, 152000L, 138000L, 140000L, 137000L, 133000L, 126000L, 102000L, 82900L, 133000L, 158000L, 116000L, 145000L, 151000L, 125000L, 130000L, 116000L, 137000L, 133000L, 129000L, 128000L, 126000L, 135000L, 136000L, 153000L, 172000L), tempMax = c(4.6, 4.7, 4.6, 4.6, 4.4, 4.4, 4.4, 4.5, 4.4, 4.5, 4.6, 4.6, 4.6, 4.6, 4.6, 4.4, 4.4, 4.4, 4.4, 4.4, 4.5, 4.5, 4.5, 4.4, 4.3, 4.3, 4.2, 4.1, 4.1, 4.1, 4.1, 4, 3.9, 3.8, 3.6, 3.5, 3.2, 2.8, 2.7, 2.6, 2.6, 2.5, 2.6, 2.7, 2.8, 2.7, 2.4, 3, 3, 2.9, 3.1, 3.2, 3.3, 3.4, 3.4, 3.4, 3.6, 3.9, 4.1, 4.3, 4.2), tempMin = c(4.5, 4.5, 4.5, 4.4, 4.3, 4.2, 4.3, 4.4, 4.4, 4.3, 4.5, 4.4, 4.5, 4.5, 4.4, 4.3, 4.3, 4.3, 4.3, 4.4, 4.4, 4.4, 4.4, 4.3, 4.3, 4.2, 4.1, 4, 4, 4, 4, 3.9, 3.8, 3.6, 3.5, 3.2, 2.8, 2.7, 2.5, 2.4, 2.4, 2.4, 2.4, 2.5, 2.6, 2.4, 2.3, 2.4, 2.8, 2.7, 2.8, 2.9, 3.1, 3.2, 3.4, 3.4, 3.4, 3.6, 3.9, 4.1, 4), tempMean = c(4.5, 4.6, 4.6, 4.5, 4.4, 4.3, 4.4, 4.4, 4.4, 4.4, 4.5, 4.5, 4.5, 4.5, 4.5, 4.4, 4.3, 4.3, 4.4, 4.4, 4.4, 4.5, 4.5, 4.4, 4.3, 4.3, 4.2, 4.1, 4, 4, 4, 4, 3.8, 3.7, 3.5, 3.3, 3, 2.8, 2.6, 2.5, 2.5, 2.5, 2.5, 2.6, 2.7, 2.5, 2.4, 2.7, 2.9, 2.8, 2.9, 3.1, 3.2, 3.3, 3.4, 3.4, 3.5, 3.7, 4, 4.2, 4.1 )), .Names = c("date", "disch", "tempMax", "tempMin", "tempMean" ), row.names = 732:792, class = "data.frame") Where have I erred in this process? And, how do I correctly convert a data from to a ts class for plotting and analyses? Rich
Rich Shepard
2014-Mar-04 17:05 UTC
[R] From data frame to time series matrix and plot [UPDATE]
On Mon, 3 Mar 2014, Rich Shepard wrote:> I would like to plot (separately) time series for the 'disch' and > 'tempMean' columns but have not had success in passing the correct syntax to > the plot() function and having the x-axis labels as human-readable dates > rather than the epoch time (which is what I assume is in the date class).Significant progress has been made, but I'm still not using the correct syntax. 1) I modified the original data frame to 3 columns: date, disch, and temp. 2) Using ts() I converted the data frame to a ts object. 3) After reading ?plot.ts and ?ts.plot I determined that the latter is appropriate for a multivariate time series on a single set of axes: plot.ts(col.riv.ts, plot.type = "single", xylabels = c("Date","Amount")) Warning messages: 1: In plot.window(xlim, ylim, log, ...) : "xylabels" is not a graphical parameter 2: In title(main = main, xlab = xlab, ylab = ylab, ...) : "xylabels" is not a graphical parameter 3: In axis(1, ...) : "xylabels" is not a graphical parameter 4: In axis(2, ...) : "xylabels" is not a graphical parameter 5: In box(...) : "xylabels" is not a graphical parameter But, not only have I not correctly specified xylabels, but the dates are not correctly presented (that is, as dates rather than numbers), and there are other options which I need to better understand. Would xyplot() be a better function for these data? Rich -------------- next part -------------- A non-text attachment was scrubbed... Name: col.riv.ts-1.pdf Type: application/pdf Size: 13310 bytes Desc: URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20140304/af040cbd/attachment.pdf>
Rich Shepard
2014-Mar-04 18:24 UTC
[R] From data frame to time series matrix and plot [RESOLVED]
On Mon, 3 Mar 2014, Rich Shepard wrote:> I'm missing something simple here so a pointer is needed.Figured it out: I created two ts() objects, one for each parameter, then plotted them using cbind. Just need to tweak how the dates display on the x axis, but that should be doable. Rich