[R] Identify and plotting symbols.
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Sep 20 09:18:39 CEST 2007
On Thu, 20 Sep 2007, Rolf Turner wrote:
> I have been trying, unsuccessfully, to use identify() to (simply) return
> a list of the indices of points clicked on and overplot (with say a
> solid dot) each clicked-on point so that I can see where I've been.
> I.e. I don't want to see the indices printed on the screen; I just want
> the points I've already selected to be highlighted.
>
> I tried
>
> ind <- identify(x,y,labels=rep("\021",length(x)),offset=0)
>
> Two problems:
>
> (1) Instead of getting a solid dot --- which I thought I should
> get from "\021", I got a small rectangle outlined in dotted lines.
> (Which I would've thought I'd get from "\177".)
Why did you think so?
What glyphs (if any) you get from non-ASCII characters depends on the OS,
locale, graphics device and font, none of which we know.
(It can be even more specific than that: it may depend on what font
variants you have installed, as on both X11 and Windows there can be
multiple fonts of the same name with different encodings.)
In particular in a UTF-8 locale (and you seem latterly to be using MacOS X
which has UTF-8 locales), you probably need to select characters by
Unicode points, e.g. \u2022 or \u22c5.
> I seem to get the dotted rectangle no matter what 3 digit string I
> use in "\xxx".
I am surprised: does "\088" not give "H" ?
> (2) Despite setting offset=0 the superimposed symbol is not
> actually superimposed, but is jittered off the location of the existing
> point by a small amount.
Ah, what do you mean by 'superimposed'? What you should find is the
appropriate edge of the bounding box of the character is on the point
identified. See the 'value' section of the help page for what is meant by
'appropriate edge'.
> Another minor annoyance is having to use rep("\021",length(x)) rather
> than simply "\021". I.e. the vector supplied for labels does not get
> ``recycled'' the way col and pch etc. are recycled.
Which is as documented, and contrasts with e.g. text() which says its
'labels' argument is recycled.
> Is there any way of resolving these difficulties?
Yes, use identify(plot=FALSE) in a loop and manage the plotting yourself.
Something like
myidentify <- function(x, y, pch=19, n, ...)
{
res <- integer(0)
for(i in seq_len(n)) {
ans <- identify(x, y, plot=FALSE, n=1, ...)
if(length(ans) == 0) break
points(x[ans], y[ans], pch=pch)
res <- c(res, ans)
}
res
}
and you can refine this by using xy.coords and not allowing repeats.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list