[R] Annoteting graphs using text

Craig H. Ziegler chzieg01 at athena.louisville.edu
Fri Nov 7 18:49:19 CET 2003

Dear All,

I am new to R and am trying to learn how to create functions using R.
Below is code which calculates Lin's Concordance Coefficient.  After
I calculate the coefficient I want to create a scatter plot which
annotates the coefficient along with preceding text onto the plot.
The below code doesn't seem to work.  If I use only the object
'lincc' on the text command it works (but doesn't give me the preceding
text) or if I use only "Lin's Concordance Coefficient = " on the text
command it works (but doesn't place on the plot the value for the object
'lincc').  Similarly, I have tried using:
          linc=cat("Lin's Concordance Coefficient = ",lincc)
within the function and then specifying:

Also, the objects I create inside a "user defined function"
are internal to the function.  Is there anyway/command that
can make them external, i.e., make them exists to perform
tasks on outside the user defined function.

Can anyone offer some advise as to what I am doing wrong?


Craig Ziegler
# o1 is the x vector
# o2 is the y vector
# I am trying to correlate these vectors to get
# Lin's Concordance Coeffient.  These are just
# test vectors

#title is a specification for the plot title; see 'main = title' in the
#plot function
#hlab is the x axis label; see "xlab = hlab" in the plot function
#vlab is the y axis label; see "ylab = vlab" in the plot function

title="This is a test plot"
vlab="Label for verticle axis"
hlab="Label for horizontal axis"

# Start of the function I call lin

lin = function (x,y)
      lincc =
              (2 * cov(x,y)) /
              (var(x) + (var(y)) +
	      ((mean(x) - mean(y))^2))

       agree =
	       main = title, xlab = hlab, ylab = vlab )

               #Below is where I am having trouble as discussed above

               text(20,60,cat("Lin's Concordance Coefficient = ",lincc))

#executes the function

More information about the R-help mailing list