Skip to content
Prev 377501 / 398502 Next

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

I assume that you are importing the Excel sheets separately. When you
import a sheet, you can get the number of columns with this:

ncol(<name of data frame>)

Using the data frame "mpg" that I created:

ncolumns<-ncol(mpg)
ncolumns
[1] 38

You can then substitute "ncolumns" each time you import another sheet. How
you want to deal with the varying numbers of columns you will get is
another matter. One way is to work out the total number of plots you want
and put them all onto one PDF page. Say you have 50 plots overall. You
could start a very big PDF page:

pdf("allplots.pdf",width=30,height=15)
par(mfrow=c(5,10))
# import your first sheet here (38 columns)
ncolumns<-ncol(mpg)
for(i in 1:ncolumns)
 plot(seq(1,500,length.out=10),mpg[,i],type="l",xlab="Distance",
  ylab="MPG",main=names(mpg)[i])# import your second sheet here, say 10
columns
# import your second sheet here, (10 columns)
ncolumns<-ncol(mpg1)
for(i in 1:ncolumns)
 plot(seq(1,500,length.out=10),mpg1[,i],type="l",xlab="Distance",
  ylab="MPG",main=names(mpg)[i])# import your third sheet here, say 2
columns
# import your second sheet here, (2 columns)
ncolumns<-ncol(mpg2)
for(i in 1:ncolumns)
 plot(seq(1,500,length.out=10),mpg2[,i],type="l",xlab="Distance",
  ylab="MPG",main=names(mpg)[i])
# finish plotting
dev.off()

You would then have 50 plots on the PDF page. I am assuming that all of
your sheets have the same number of rows and a few other things. This seems
like a lot of plots, and I suspect that you could work out a better way to
display all this information.

Jim


On Wed, Nov 21, 2018 at 1:20 PM Subhamitra Patra <subhamitra.patra at gmail.com>
wrote: