On Jan 24, 2012, at 8:12 AM, ksaw wrote:
> Dear R-helpers,
>
> I am trying to add an information about the mean value for each
> variable
> within each plot by adding text to the multiple plots in this way:
>
> par(mfrow=c(2,2))
> df$Date <- as.Date(df$Date, format="%d/%m/%Y")
>
> for (i in 2:5){
> plot(df$Date, df[[i]])
> Mean <- mean(na.omit(df[[i]]))
> text(x=max(na.omit(df[[i]])), labels=paste("Mean = ", Mean,
sep=""))
> }
>
> where df is an example table:
> Date A B C D
> 01/12/2008 3 6 3 6
> 14/12/2008 4 7 4 7
> 27/12/2008 4 5 65 8
> 09/01/2009 5 5 7 6
> 22/01/2009 23 4 8 6
> 04/02/2009 2 3 5 2
> 17/02/2009 4 65 4 2
> 02/03/2009 5 6 3 2
> 15/03/2009 5 7 3 5
> 28/03/2009 6 7 2 5
> 10/04/2009 78 5 2 6
> 23/04/2009 3 3 1 NA
> 06/05/2009 4 3 4 6
>
> It does work if the Date is not in a date format. When changing the
> Date
> format into date there is no output from text within a loop.
Most likely because the plot is being constructed with dates as the x-
value and your `text` call has the x's as what you are considering to
be the y-values.
> Is there a way
> to keep the date format as.Date and be able to print the information
> about
> the mean on each plot?
>
> Many thanks
> Kasia
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/Adding-text-to-multiple-plots-tp4323717p4323717.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT