Hi all,

I am trying to print some generated text on plot which is comprised of text and the value of a variable. Thanks to the response from Joshua Wiley <jwiley.psych@gmail.com> on the thread "How to format R superscript 2 followed by "=" value, I can now get R^2 = value. However with the following code:

ggplot(blData, aes(x = xData, y = yData)) +
    geom_point(aes(colour = factor(diagnosis))) +
    geom_smooth(method = "lm") +
    opts(legend.position = c(0.75, 0.25)) +
    scale_colour_discrete(name = "Diagnosis") +
    labs(x = r2format(t0.lm, output = "R^2 == rval", sub = "rval")) + #"Baseline - Automated", y = "Baseline - Manual") +
    annotate("text", x = 1.35, y = 2.5,
             label = r2format(t0.lm, output = "R^2 == rval", sub = "rval"))
             #paste("R^2 = ", t0.rsq, sep = ""))

I can get the text on the x-axis OK, but the annotation in the plot does not show up. If I replace the label with the commented out section,  the text shows on the graph.

Here is a repost of Joshua's code:
################################
## function definition
r2format <- function(object, digits = 3, output, sub, expression = TRUE, ...) {
 if (inherits(object, "lm")) {
   x <- summary(object)
 } else if (inherits(object, "summary.lm")) {
   x <- object
 } else stop("object is an unmanageable class")
 out <- format(x$r.squared, digits = digits)

 if (!missing(output)) {
   output <- gsub(sub, out, output)
 } else {
   output <- out
 }
 if (expression) {
   output <- parse(text = output)
 }
 return(output)
}

Is there an option I have missed?

Many thanks,
Noel Faux

----
NHMRC Post Doctoral Fellow
Australian Imaging Biomarker Lifestyle (AIBL) flagship
Mental Health Research Institute
The University of Melbourne
----
155 Oak St, Parkville
Victoria 3052
Australia
T: +613 9389 2943
----
National Neuroscience Facility
Level 3, Alan Gilbert Building
161 Barry Street, Carlton
Victoria 3010
Australia
T: +613 8344 1944
e-mail: nfaux@unimelb.edu.au
www.mhri.edu.au
biocoder: http://biocoders.net/members/nfaux/
----------------
This email and any attachments are confidential. They ma...{{dropped:14}}

