Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

exposing gri's tukey plot values to the user

Help
tom_strang
2006-04-13
2013-04-24
  • tom_strang
    tom_strang
    2006-04-13

    Hi, I've used Gri for many years now to do my graphs for publication and I am always impressed that I can 'get there from here' with it. But now I'd like to pull the values that Gri calculates for the tukey box plots out to tabulate them, as I currently have hundreds of values being plotted for visual comparison but need the values to drive further plotting functions. Is there a way you can envision I go about this. I know the relevant code for the plots and statistics are in draw_x_box_plotCmd() and histogram_stats()
    but getting values up to the interface to be available as something like ..q1.. etc is beyond my knowledge of gri internals at this point.

    Exposing any internal statistics calculated on data as a variable to be read for labeling, or writing to file for tables would be a very convenient element to avoid using an outside package to do it again. My colleague showed
    me how Sigmaplot seems capable of it, so I want Gri to do it too to avoid changing back after eight happy years away from Sigmaplot :-)

    In your view, would this be relatively easy to do, and worthwhile for others?

    Thanks,
    Tom

     
    • Dan Kelley
      Dan Kelley
      2006-04-13

      Yes, I think it would be nice for some sort of general exposure of things.  There is an issue of namespace pollution, however.  For example, a given procedure might define  a variable named ".max." that might over-ride a definition made by another procedure.  Perhaps a good scheme might be to use a namespace for the previous command, e.g. after doing a gri command, any variables defined within that command would be stored in names such as ".last_cmd:VAR.", where "VAR" is the more meaningful name.

      So, you've given me something to "chew on".

      In the meantime, I think you can accomplish your particular task quite easily, with a little knowledge of programming.  To illustrate, let me show what I just did, as a test for your particular case.  (NOTE: the changes I made to the code did NOT go back into the official gri package.  This was just a local modification.  If you end up doing such things, you should learn about the "patch" command, and save your modifications in patches, so that you can update your personalized actions as new versions of gri are released.)

      OK, now, here's what I did for your example (in unix)...

      1) Do
          grep -n box_plot *
      and see that draw.cc is handling this at line 2758 (for x direction) and 2912 (for y).

      2) edit draw.cc:2758 and verify that it's the right place.  Page down to see that the work seems to be done in something called
          histogram_stats

      3) Do
          grep -n histogram_stats *cc
      to find that this is defined in stats.cc:57 ... well, maybe let's not mess that up, but let's go back to draw.cc ...

      4) Add two lines after draw.cc:2815, so that it reads

             // figure statistics
              histogram_stats(_colX.begin(), _colX.size(), &q1, &q2, &q3);
              PUT_VAR("..q1..", q1);
              PUT_VAR("..q2..", q2);
              PUT_VAR("..q3..", q3);

      5) Recompile

      6) test on e.g. the following

      read columns x
      1.3
      3.2
      2.1
      3.9
      4.3
      0.1

      set y axis 0 1
      draw x box plot at 0.5
      show variables

      7)  post this message :-)

       
    • tom_strang
      tom_strang
      2006-04-20

      Thanks Dan,
      It worked cleanly and I get a useful text dump of my values using the 'show' command. My follow on question is, how can I then print the values onto the plot in one pass? Is there a way to convert a value to a string in Gri so I can drop it into `draw label at..'

      Tom

       
      • Dan Kelley
        Dan Kelley
        2006-04-20

        Sure.  Do as follows.

        .pi. = 3.14
        sprintf \txt "%.1f" .pi.
        draw label "\txt" at 3 1 cm