[R] Using locator() to digitise

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Sun Mar 20 17:09:11 CET 2005


Hi Folks,

I'm contemplating using locator() to digitise external
graphics. To set context, I would be using X11 display
on Linux.

To pre-empt the obvious comment: I've found on the R site
the suggestion to use the 'pixmap' package. I've tried
this, and it works; but it involves building a big R
object (the internal pixmap representation), and this
chokes my somewhat puny laptop (e.g. it can take about
1 minute to draw the graphic inside a plot area using
addlogo(), with mucho swappo, and subsequently working
knee-deep in treacle). The following idea would be a lot
slicker.

For examples: I have something like

a) A scatterplot of data printed in a journal (but the
   data values are not available;

b) A contour map (on paper) of a region.

So, I can scan the document, and obtain a file in some
graphics format (jpeg, pbm or png, say).

Now: an idea which I find attractive is to be able to
overlay an R plot with axes onto a display of the graphics
file (produced as an X window by any suitable program such
as 'xv' or 'display') so that (if the overlay were possible)
clicking on the points of the graphic would in fact be
clicking on the R plot and, via locator(), generate the
R-plot coordinates of the mouse clicks which would correspond
to the selected points on the graphic.

Provided the coordinate system of the R plot were properly
related to the graphic, the results would be a digitisation
of the selected points on the graphic.

What seems to be needed for this idea to work is that
the R-plot should be displayed in an X11() device whose
background was completely transparent, so that when
moved over the (independently generated) display of the
graphic the latter would be visible (but locator() would
still be working on the R-plot itself). Window resizing
could look after the correspondence between graphic coordinates
and R-plot coordinates.

The R plot itself could be empty (apart from coordinate axes)
or could contain "helper" elements such as grid lines, circles
(e.g. I want to digitise graphics points within a certain circle),
etc. "Helper" elements could be added to the R-plot by subsequent
'lines' or 'points' commands (e.g. I identify two points on
the graphic, R-plot the line joining them, and then pick off
graphic-points which lie on the R-line).

So this question is really about producing a "bare" R plot
on, as it were, a virtual acrylic transparency. It's certainly
possible to do such a thing in X: e.g. the cute "xteddy" is
in fact a picture of a bear on a completely transparent
rectangular background, though you'd never know by looking!

Any comments?

With thanks, and best wishes to all,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 20-Mar-05                                       Time: 16:09:11
------------------------------ XFMail ------------------------------




More information about the R-help mailing list