R + ggplot:绘制不规则的时间序列 [英] R + ggplot: plotting irregular time series

查看:185
本文介绍了R + ggplot:绘制不规则的时间序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自事件发生以来,我有数天的数据。这些数据是不规则地采样 - 我的时间点是0,5,6,10,104天。我没有具体的日期 - 时间信息 - 即我不知道在现实生活中发生了我正在学习的事件。



我想用ggplot绘制我的时间系列。我可以使用,比如说

  p < -  ggplot(data,aes(x = time,y = expression))
p < - p + geom_point()

但是我的x轴变量当然是绘制的彼此之间,使得t = 10和t = 104之间的距离与t = 5和t = 6相同。因此,我可以做一些类似于

  start<  -  ISOdate(2001,1,1,tz =)
data $ time< - start + data $ time * 60 * 60 * 12

工作,但现在我的X轴上的蜱是非常不准确的日期时间。我可以重新格式化它们吗?但无论如何看不到格式开始的日子。到现在为止,我一直在使用Google搜索了很长一段时间,有一种唠叨的感觉,我错过了一些非常明显的东西。我是吗?

也许是一个字符矢量,而不是数值!如果你做了 data $ time< - as.numeric(data $ time),它可以很好的解决你的问题。



< ggplot非常适合使用正确类型的比例来处理正确的数据。 (可惜的是,R中的数据导入例程通常不那么聪明......)

I have data at a number of days since an event. This data is sampled irregularly - my time points are like 0, 5, 6, 10, 104 days. I don't have specific date-time information - i.e. I have no idea when in real life the event I'm studying occurred.

I'd like to plot, using ggplot, my time series. I can use, say

p <- ggplot(data,aes(x=time,y=expression))
p <- p + geom_point()

but of course my x-axis variables are plotted next to each other, so that the distance between t=10 and t=104 is the same as t=5 and t=6. So I can make something up like

start <- ISOdate(2001, 1, 1, tz = "")
data$time <- start + data$time*60*60*12

which almost works, but now the ticks on my x-axis are horribly inaccurate date times. I could re-format them maybe? But can't see anyway to make the format "days from start". And by now I've been googling around for quite a while, with the nagging feeling that I'm missing something seriously obvious. Am I?

解决方案

Sounds like your time variable is a factor or maybe a character vector, not a numeric value! If you do data$time <- as.numeric(data$time) it may well solve your problem.

ggplot is pretty good at using the right sort of scale for the right sort of data. (Sadly, data import routines in R generally are less smart...)

这篇关于R + ggplot:绘制不规则的时间序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆