[R] [R studio] Plotting of line chart for each columns at 1 page
Jim Lemon
drjimlemon @ending from gm@il@com
Sun Dec 16 03:40:10 CET 2018
Hi Subhamitra,
Thanks. Now I can provide some assistance instead of just complaining. Your
first problem is the temporal extent of the data. There are 8613 days and
6512 weekdays between the two dates you list, but only 5655 observations in
your data. Therefore it is unlikely that you have a complete data series,
or perhaps you have the wrong dates. For the moment I'll assume that there
are missing observations. What I am going to do is to match the 24 years
(1994-2017) to their approximate positions in the time series. This will
give you the x-axis labels that you want, close enough for this
illustration. I doubt that you will need anything more accurate. You have a
span of 24.58 years, which means that if your missing observations are
uniformly distributed, you will have almost exactly 226 observations per
year. When i tried this, I got too many intervals, so I increased the
increment to 229 and that worked. To get the positions for the middle of
each year in the indices of the data:
year_mids<-seq(182,5655,by=229)
Now I suppress the x-axis by adding xaxt="n" to each call to plot. Then I
add a command to display the years at the positions I have calculated:
axis(1,at=year_mids,labels=1994:2017)
Also note that I have added braces to the "for" loop. Putting it all
together:
year_mids<-seq(182,5655,by=229)
pdf("EMs.pdf",width=20,height=20)
par(mfrow=c(5,4))
# import your first sheet here (16 columns)
EMs1.1<-read.csv("EMs1.1.csv")
ncolumns<-ncol(EMs1.1)
for(i in 1:ncolumns) {
plot(EMs1.1[,i],type="l",col = "Red", xlab="Time",
ylab="APEn", main=names(EMs1.1)[i],xaxt="n")
axis(1,at=year_mids,labels=1994:2017)
}
#import your second sheet here, (1 column)
EMs2.1<-read.csv("EMs2.1.csv")
ncolumns<-ncol(EMs2.1)
for(i in 1:ncolumns) {
plot(EMs2.1[,i],type="l",col = "Red", xlab="Time",
ylab="APEn", main=names(EMs2.1)[i],xaxt="n")
axis(1,at=year_mids,labels=1994:2017)
}
# import your Third sheet here, (1 column)
EMs3.1<-read.csv("EMs3.1.csv")
ncolumns<-ncol(EMs3.1)
for(i in 1:ncolumns) {
plot(EMs3.1[,i],type="l",col = "Red", xlab="Time",
ylab="APEn", main=names(EMs3.1)[i],xaxt="n")
axis(1,at=year_mids,labels=1994:2017)
}
# import your fourth sheet here, (1 column)
EMs4.1<-read.csv("EMs4.1.csv")
ncolumns<-ncol(EMs4.1)
for(i in 1:ncolumns) {
plot(EMs4.1[,i],type="l",col = "Red", xlab="Time",
ylab="APEn", main=names(EMs4.1)[i],xaxt="n")
axis(1,at=year_mids,labels=1994:2017)
}
# finish plotting
dev.off()
With any luck, you are now okay. Remember, this is a hack to deal with data
that are not what you think they are.
Jim
[[alternative HTML version deleted]]
More information about the R-help
mailing list