Skip to content
Prev 377493 / 398502 Next

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

Dear R users,

I have one excel file with 5 sheets. The no. of columns vary for each
sheet. The 1st sheet consists of 38 columns. So, I want to plot 38 separate
line charts and arrange them in par(mfrow = c(4, 10)) order. Please suggest
me how to do this. I have tried with the following code by running a loop
inside of a sheet, but it is not working. Further, I want to run loops for
each sheet.

par(mfrow = c(4, 10))
loop.vector <- 1:38
for (i in loop.vector)
x <- JJ[,i]
library(ggplot2)
  library(cowplot)
  plot.mpg <- ggplot(mpg, aes(x,
                              main = paste ("country", i),
                              xlab = "Scores",
                              xlim = c(1,500)
                              y = colnames[i,], colour = factor(cyl))) +
  geom_line(size=2.5)
save_plot("mpg.png", plot.mpg,
          base_aspect_ratio = 1.3)

I want to give my X axis name as scores of (1,500) and Y axis as the
particular column names for all graphs.

Please suggest.

Thanks in advance.