[R] Extending a plot in a loop (With attachment)

Peter Alspach Peter.Alspach at plantandfood.co.nz
Tue Nov 16 20:35:42 CET 2010


Tena koe Nasrin

Try points() instead of plot() in your second and subsequent calls to plot().  points() and lines() adds to the current plot by default.  Of course you may have difficulties with setting the x and y limits by that's another matter.

HTH ....

Peter Alspach

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Nasrin Pak
> Sent: Wednesday, 17 November 2010 7:24 a.m.
> Cc: r-help at r-project.org
> Subject: [R] Extending a plot in a loop (With attachment)
> 
> My problem is that I have a data set for every day of measurement in a
> seperate file and I want to plot one parameter of the data for all the
> days in one graph. I tried to use for loop but only the last data
> remains in the program memory, I don`t know how to plot each day`s data
> continusly after the others(or how to extending the x axis.) Would you
> please help me with it?
> 
> This a plot for one day:
> 
> radiation.data
> <-read.table("C:/updated_CFL_Rad_files/2008/RAD_2008_JD101_0410.dat",
> header = TRUE,sep = ",", quote = " ", dec = ".")
> > attach(radiation.data)
> The following object(s) are masked from 'radiation.data (position 3)':
> 
>     Batt_avg, Batt_st, Day, Hour, Kdown_avg, Kdown_st, LW_in, LW_in_st,
>     Minute, Month, PanelT_avg, PanelT_st, PAR_avg, PAR_st, Sec,
>     Tcase_avg, Tcase_st, Tdome_avg, Tdome_st, Thermopile_avg,
>     Thermopile_st, Tuv_avg, Tuv_st, Uva_avg, Uva_st, Uvb_avg, Uvb_st,
>     Year
> > names(radiation.data)
>  [1] "Year"           "Month"          "Day"            "Hour"
>  [5] "Minute"         "Sec"            "Batt_avg"       "PanelT_avg"
>  [9] "Batt_st"        "PanelT_st"      "Kdown_avg"
> "Thermopile_avg"
> [13] "Tcase_avg"      "Tdome_avg"      "LW_in"          "PAR_avg"
> [17] "Tuv_avg"        "Uvb_avg"        "Uva_avg"        "Kdown_st"
> [21] "Thermopile_st"  "Tcase_st"       "Tdome_st"       "LW_in_st"
> [25] "PAR_st"         "Tuv_st"         "Uvb_st"         "Uva_st"
> 
>  plot(((PAR_avg*0.216)/Uvb_avg),
> main="Par/UVB",xlab="minutes",ylab="Par/UVB")
> 
> 
> and this is the algorithm I tried  for plotting all the data in one
> plot:
> 
> x<- matrix( list.files("C:/updated_CFL_Rad_files",full=TRUE)) # putting
> all data sets in a matrix
>   for(i in 1:100) {
>       if(i < 101) next
>      radiation.data <-read.table(x[i], header = TRUE,sep = ",", quote =
> " ", dec = ".")
>  attach(radiation.data)
>  plot(i*Hour*60+Minute,PAR_avg,main="PAR",xlab="Hour",ylab="Par")
> dev.print(device=postscript, "C:/graph5.eps", onefile=FALSE,
> horizontal=FALSE)
>        }
> The plot I see is the last file's plot, I don't know how to keep
> previous data and continue within the same plot.
> 
> * I have attached a sample of the data to this email.
> 
> --
> Sincerely
> 
> Nasrin  Pak
> 
> 
> 
> 
> 
> 
> 
> --
> Sincerely
> 
> Nasrin  Pak

The contents of this e-mail are confidential and may be subject to legal privilege.
 If you are not the intended recipient you must not use, disseminate, distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received this
 e-mail in error, please notify the sender and delete all material pertaining to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.



More information about the R-help mailing list