Reputation: 21
I have a list of about 50 values and corresponding non-continuous dates in a pdf of which I need to make a time series graph in R. How do I do this?
No response can be too detailed or basic. Thanks.
Upvotes: 2
Views: 1651
Reputation: 263352
I agree with PaulHurleyuk that your question is ambiguous because of the term "pdf". It's also ambiguous in how you want to represent the non-continuous aspect. If you want to just plot values as lines and ignore spacing but do not have NA values then this works:
dataset <- data.frame(Date = as.Date(Sys.Date()+sample(1:75, 50)),
Value = rnorm(50))
plot(dataset[order(dataset[,1]), ], type="l")
If you want to have discontinuities at the date where there are NA values, and you want to have gaps in the plotted values, then:
dataset <- data.frame(Date = as.Date(Sys.Date()+1:50), Value = rnorm(50))
dataset[sample(1:50, 10), 2] <- NA
plot(dataset[order(dataset[,1]), ], type="l")
Upvotes: 3
Reputation: 18487
library(ggplot2)
library(chron)
dataset <- data.frame(Date = as.Date(chron(runif(50, 0, 365))), Value = rnorm(50))
ggplot(dataset, aes(x = Date, y = Value)) + geom_line()
Upvotes: 1