1

I am using this code for plotting list of variables in a single page:

plot30 <- list(HMn25_30,HMn28_30,HMn29_30,HMn31_30,HMn32_30)

par(mfrow=c(2,3))
for (i in plot30)  {
  plot(i, type = "o", pch = 16, lty = 2, col = "Black", xlab = "Hour  2007/09/30" , ylab = "Ambient Tempreture")
}

Result of this code: enter image description here

I wanted to add titles such as {Node 25,Node 28,Node 29,Node 31,Node 32} to the plots.

Any suggestion?

Topdombili
  • 265
  • 4
  • 10
  • Suggestion: Read `?plot` and take note of the `main` argument. (You'll need to use a different index variable in your for loop.) – joran Jan 09 '13 at 20:39

2 Answers2

3

try to add the following in your for loop

plot30 <- list(HMn25_30,HMn28_30,HMn29_30,HMn31_30,HMn32_30)
Main <- c('Node 25','Node 28','Node 29','Node 31','Node 32')

par(mfrow=c(2,3))
for (i in seq_along(plot30))  {
  plot(plot30[[i]], type = "o", pch = 16, lty = 2, col = "Black", xlab = "Hour  2007/09/30" , ylab = "Ambient Tempreture", main=Main[i])
}
Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
  • Thanks, but I came up with this error: Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but does not have components 'x' and 'y' – Topdombili Jan 09 '13 at 20:54
  • 2
    @Topdombili If your example had been reproducible, Jilber would have caught the typo and used `[[` instead of `[`. This is why it is in _your_ best interest to provide reproducible code: you'll get better answers. – joran Jan 09 '13 at 20:57
  • Yes, @joran is right, since you Topdomili didn't give us a reproducible example the code I gave is not tested ;) – Jilber Urbina Jan 09 '13 at 20:58
  • Would you please calrify what do you mean by reproducible code? – Topdombili Jan 09 '13 at 21:00
  • @Topdombili I should be able to copy and paste your code into an R session and run it completely and see exactly the behavior your see. – joran Jan 09 '13 at 21:02
  • See [this post](http://stackoverflow.com/q/5963269) for a detailed explanation on what a [reproducible example](http://stackoverflow.com/q/5963269) is – Jilber Urbina Jan 09 '13 at 21:02
2

This is the construct you should expand from:

plot30 <- list(myplot)
names(plot30)<- c('myplot1') 
for (i in seq_along(plot30) )  {pname <- names(plot30)[i]
  plot(plot30[i],  main=pname)
}
IRTFM
  • 258,963
  • 21
  • 364
  • 487