[英]Plot two line graphs within one chart with shared time x-axis in R axis.Date not working
[英]R pot.ts of multiple graphs and mapping time/date to x-axis from vector
我正在使用plot.ts函数基于一个数据帧一次绘制多个图形。
data.frame的原始格式有以下4列:
1)日期/时间字符串2)以haP表示的压力3)湿度4)温度
用于绘制的内容不包括1):我可以将日期字符串列成功转换为ar date。 我将其存储到向量中。
我想绘制一个图形,其中精确地将2/3/4和1)作为日期/时间值映射到x轴。
我该如何实现? 我可以使用plot.ts吗?
亲切的问候,亚历克斯
我认为您应该根据自己的数据创建一个Zoo对象,并使用日期作为索引。
> 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
这将日期放在x轴上,其中df[a]
和df[b]
位于2个子图中。
编辑:如果您不熟悉Zoo类:它基本上是一个时间序列,可以为其索引保留日期(或其他内容)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.