简体   繁体   中英

R pot.ts of multiple graphs and mapping time/date to x-axis from vector

I am using plot.ts function to plot multiple graphs at once based on a dataframe.

The data.frame has in its raw format these 4 columns:

1) date/time string 2) pressure in haP 3) humidity 4) temperature

the one used to plot does not include 1): I can transform the date string column to ar date successfully. I store it into a vector.

I would like to plot a graph with exactly 2/3/4 and 1) mapped as date/time values to the x-axis.

How can I achive this? Can I use plot.ts?

Kind regards, Alex

I think you should create a zoo object from your data and use the dates as the index of that.

> df
  a b
1 1 1
2 2 2
3 3 2
4 4 1
> d <- c('2012', '2013', '2014', '2015')
> z <- zoo(df, order.by = d)
> z
     a b
2012 1 1
2013 2 2
2014 3 2
2015 4 1
> plot(z)     # This uses plot.zoo

That puts the dates on the x-axis, with df[a] and df[b] in 2 subplots.

EDIT: In case you are not familiar with the zoo class: it is basically a time series that can keep dates (or other stuff) for its index.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM