I would like to plot stack series line graph in same plot. I have been reading around at this forum and tried several mentioned examples. But, I have no luck to get it right.

This is a summary of my data in R:

> head(allPAL.DE)
               time02H       time06H       time24H
TT000526   -0.01106224     1.0080723     0.8315261
TT000561   -0.30812201    -0.4085618     0.5446794
TT000794    1.22833349     3.3781206     2.5952071
TT000197   -0.23966166    -0.2603373     0.5623011
TT000238   -0.33446383     0.6522561     0.5815776
TT000684    0.73437943     1.3070386    -1.2774730

It is a data frame R object:

> str(allPAL.DE)
'data.frame':   15 obs. of  3 variables:
 $ time02H: num  -0.0111 -0.3081 1.2283 -0.2397 -0.3345 ...
 $ time06H: num  1.008 -0.409 3.378 -0.26 0.652 ...
 $ time24H: num  0.832 0.545 2.595 0.562 0.582 ...

I wish to produce a stack series line graph like below with R:

stack series line graph

Could the community kindly share with me the way to produce aforementioned graph in R?

Thank you very much for your time.

有帮助吗?

解决方案

Here is some code that will give you what you want.

#Example Data
n = 6
time02H = abs(rnorm(n))
time06H = abs(rnorm(n))
time24H = abs(rnorm(n))

allPAL.DE = data.frame(time02H,time06H,time24H)

plot(0,0,xlab="Time",ylab="Values",type="n",xlim=c(0,2),ylim=c(min(allPAL.DE,0),max(allPAL.DE)),axes="FALSE")
box()
axis(1,0:2,c("time02H","time06H","time24H"))
axis(2)
abline(h=0,col="grey",lty=2,lwd=2)

for(i in 1:nrow(allPAL.DE)){
    lines(0:2,allPAL.DE[i,],col=i,lwd=2)
}

You could add different options, colors and text to make the plot look nicer but its the basic idea that you were asking for.

enter image description here

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top