开发者

Easiest way to create an irregular time series graph (R? GGPLOT? ITS?)

I'm a graphic designer who is trying to use R to create graphs that are too complicated for Excel. I'm specifically trying to create an irregular time series step chart. I've had no problems creating a regular time series chart, but for some reason, the irregular dates are throwing everything off.

I'm starting with a basic text file with two columns of data:

01-04-1940    4
05-29-1963    35
12-02-2002    24

I've loaded the data using

d <- read.delim("file.txt", header = TRUE)

and I've converted the first column in Unix time using

d$date <- as.Date(d$date, format = "%m-%d-%Y")

But at this point, I can't find any more information anywhere on how to proceed. I've seen 开发者_高级运维the R package "ITS," But I cannot find any documentation on it beyond technical descriptions of the classes involved.

I'd much appreciate it if someone with some experience in R could point out the few lines of code I need to create this graph. Thanks!


ggplot deals quite nicely with data in date format. Here are some suggestions:

d <- data.frame(
    date = c("01-04-1940", "05-29-1963", "12-02-2002"),
    value = c(4, 35, 24)
)

d$date <- as.Date(d$date, format = "%m-%d-%Y")

ggplot(d, aes(x=date, y=value)) + geom_step(colour="blue")

Easiest way to create an irregular time series graph (R? GGPLOT? ITS?)

ggplot(d, aes(x=date, y=value)) + geom_line(colour="red")

Easiest way to create an irregular time series graph (R? GGPLOT? ITS?)


I would use xts/zoo. They both handle irregular time series easily.

z <- zoo(d[,2], d[,1])
plot(z)
plot(z, type="s")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜