[R] Annoteting graphs using text
andy_liaw at merck.com
Fri Nov 7 19:08:02 CET 2003
You want to use paste() inside text(), not cat().
> From: Craig H. Ziegler [mailto:chzieg01 at athena.louisville.edu]
> 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
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
More information about the R-help