Skip to content
Prev 377778 / 398502 Next

[R studio] Plotting of line chart for each columns at 1 page

Hello Sir,

Thank you very much for your excellent guidance to a new R learner.

I tried with your suggested code and got the expected results, but for the
2 CSV files (i.e. EMs2.1. and EMs.3.1), the date column is not coming in
the X-axis (shown in the last row of the attached result Pdf file).  I
think I need to increase more or less than 229 in the year-mids because for
both the CSV files, starting date is 03-01-2002 and 04-07-2001
(date-month-year) for EMs 2.1. and EMs 3.1. respectively. *Sir, hence I am
quite confused for the logic behind the fixing of year_mids*. For your
convenience, I am attaching both the code and result file.

pdf("EMs1.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")
  year_mids<-seq(182,5655,by=229)
  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")
  year_mids<-seq(182,3567,by=229)
  axis(1,at=year_mids,labels=2002: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")
  year_mids<-seq(182,3698,by=229)
  axis(1,at=year_mids,labels=2001: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")
  year_mids<-seq(182,5265,by=229)
  axis(1,at=year_mids,labels=1995:2017)
}
# finish plotting
dev.off()


Sir, According to your suggestion, *"** you can do a better job of placing
the year labels by changing the sequence for each of the CSV (not Excel)
files. The best method of all would be to have a date for each observation.
You could then discard all these approximations I have made to get the
plots to work.**" , *when I am adding the date (i.e. date-month-year) in
the sequence *(**year_mids<-seq(182,5655,by=229)*
*
  axis(1,at=year_mids,labels=03-01-1994:03-08-2017)*
*
  })*
*I am getting the error.*

Kindly suggest.

Thank you very much.





[image: Mailtrack]
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
Sender
notified by
Mailtrack
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
12/17/18,
12:25:26 PM
On Sun, Dec 16, 2018 at 2:58 PM Jim Lemon <drjimlemon at gmail.com> wrote: