[R] Annoteting graphs using text
Don MacQueen
macq at llnl.gov
Fri Nov 7 19:20:41 CET 2003
Try using paste() instead of cat() in
> text(20,60,cat("Lin's Concordance Coefficient = ",lincc))
The last expression in your function will be returned as the value of
the function; that is the best way to get results out of a function
and available for use outside the function.
-Don
At 12:49 PM -0500 11/7/03, Craig H. Ziegler wrote:
>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:
> text(20,60,(linc)
>
>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?
>
>Thanks,
>
>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
>o1=c(11,9,54,55,50,44,58,5,21,58,41,59,39,34,23)
>o2=c(27,15,72,63,65,49,51,8,30,43,40,62,52,49,21)
>
>#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))
> print(lincc)
>
> agree =
> plot(x,y,xlim=c(0,70),ylim=c(0,70),
> main = title, xlab = hlab, ylab = vlab )
> abline(0,1)
>
> #Below is where I am having trouble as discussed above
>
> text(20,60,cat("Lin's Concordance Coefficient = ",lincc))
> print(agree)
> }
>
>#executes the function
>lin(o1,o2)
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
More information about the R-help
mailing list