3

I was trying to allow the user to give a curve as input for some analysis. Is there a package that can be used in this regard? Basically, a GUI like paint wherein the user can draw a simple curve and which would be stored in R as a set of data points or as an equation if its a simple curve.

Thanks Gopher

gopher kri
  • 43
  • 4

1 Answers1

1

Reading mouse input

Below is a list of sample approaches to first the problem, from the most complex to simplest (IMHO).

  1. I would recommend that you have a look at the qtpaint package.
  2. Less laborious solution may involve looking at the way interactive plots in Shiny are handled. Using the click option would enable you to get the mouse cursor position. Together with the Shiny framework this would provide a convenient wrapper to get mouse input from a user.
  3. Finally, third approach could rely on making use of the locator function available in the graphics package. Depending on what you intend to do, this may be the simplest solution as you could then use read values to inform generation of your graphic.

Generating graphics

Assuming that you got your values via the locator functionality you could attempt to draw your line using segments. It would be a little fiddly as you would have to translate your coordinates to some placement of the dot in your desired chart but this wouldn't computationally too taxing, just a matter of bring mouse pointer values to some x/y values on the chart.


If you care to update your post with a sample code and reproducible attempts of your previous work, I bet the question will receive more replies. You may find this discussion on making a reproducible example in R helpful.

Community
  • 1
  • 1
Konrad
  • 17,740
  • 16
  • 106
  • 167
  • Ah thank you very much. The locator function is exactly what I was looking for. I made a blank plot and make user select points after which the locator will save the x,y values of the points and also draw the lines between them with type="l" argument. – gopher kri Feb 11 '16 at 12:48