1
votes

I want to plot the graph for the time series data for one week, like:

Day1    Time    Day2  Time      Day3  Time.......Day7   Time
123    00:00hr  7897  00:00hr   4662  00:00hr    1235   00:00hr   
4562   01:00hr  4645  01:00hr   4564  01:00hr....7898    01:00hr
.....  .......   .... .......   ....  ...............    ......
.....  .......   ....  ......   ....  ...............       .....
.... ..... ....... ...............................................

4653   23:00    46456  23:00hr  7895  23:00hr    7892    23:00hr

I want to plot the graph for above time series data in same graph.The graph should be like it first plot the graph for Day1(of all the 24 hrs) next of it Day2,Day3...consecutively. The X-axis should be of time index,like (day1,00),(day1,01).......(day2,00)...

Please help me out of these problem

1

1 Answers

1
votes

Data generation:

set.seed(1)
df <- data.frame(matrix(round(runif(24*7,0,1000), 0), ncol=7))
colnames(df) <- paste0("Day", 1:7)
df$Time <- c(sprintf("0%d:00", 0:9), sprintf("%d:00", 10:23))
df

Here, I believe, you don't need seven Time columns with same values.

Now we can use common reshape and ggplot routine:

require(reshape2)
require(ggplot2)
mdf <- melt(df, id.vars="Time")
g <- ggplot(mdf, aes(x=1:(24*7))) + geom_line(aes(y=value))
g

Which produces the plot:

enter image description here

Some aesthetics for x axis:

g + scale_x_continuous(breaks=seq(0, 24*7, 24), labels=0:7, name="Days")

enter image description here

Basic graphics solution:

plot(mdf$value, type="l")

enter image description here