{"id":2657,"date":"2018-07-28T16:35:53","date_gmt":"2018-07-29T00:35:53","guid":{"rendered":"https:\/\/www.lunabase.org\/~faber\/blog\/?p=2657"},"modified":"2018-07-28T16:35:53","modified_gmt":"2018-07-29T00:35:53","slug":"histograms-in-grap","status":"publish","type":"post","link":"https:\/\/www.lunabase.org\/~faber\/blog\/?p=2657","title":{"rendered":"Histograms in grap"},"content":{"rendered":"<p>I know everyone loves it when I talk about arcane typesetting languages, so here&#8217;s a response to a fellow who wanted to replicate the histograms at <a href=\"http:\/\/www.jmillville.com\/project\/learnstats\/ex9.html\">http:\/\/www.jmillville.com\/project\/learnstats\/ex9.html<\/a> in grap.<\/p>\n<p>&nbsp;<\/p>\n<pre>Attached is a commented grap\/groff file that draws something like both\r\nhistograms.  I commented the grap to explain what I was up to (comments\r\nstart with .\\\"), but feel free to ask about anything that's confusing.\r\n\r\nI didn't see immediately how he set the widths of his histogram\r\nbars\/buckets, so I used 10-pound-wide buckets centered on 105,110,115...\r\nfor all crew (blue) and 5-pound-wide buckets centered on\r\n105,110,115,120... for the rowers (green).  (The bucket width is both\r\nthe clustering range and the width of the histogram bars.)\r\n\r\nI've attached the grap\/groff (called hist.ms), the data file I used\r\ncalled data, and the postscript it generates when I call\r\n\r\n$ groff -Gp hist &gt; hist.ps\r\n\r\non my ubuntu box with groff and grap installed.\r\n\r\nI used grap 1.45 from a stock ubuntu .deb.\r\n\r\nIf I wanted to do this same task as flexibly as possible, I'd probably\r\npreprocess the data using a scripting language and then generate grap\r\noutput that I'd run through groff as above.  I'm slowly writing a pic to\r\nsvg program in my spare time that would make that more portable to use.\r\n\r\nHope that helps some.<\/pre>\n<p>The grap script looks like this:<\/p>\n<pre>.G1\r\n.\\\" Initialize globals\r\ntot105 = tot115 = tot125 = tot135 = tot145 = tot155 = 0\r\ntot165 = tot175 = tot185 = tot195 = tot205 = tot215 = 0\r\n\r\nrtot105 = rtot115 = rtot125 = rtot135 = rtot145 = rtot155 = 0\r\nrtot165 = rtot175 = rtot185 = rtot195 = rtot205 = rtot215 = 0\r\nrtot110 = rtot120 = rtot130 = rtot140 = rtot150 = 0\r\nrtot160 = rtot170 = rtot180 = rtot190 = rtot200 = rtot210 = 0\r\n\r\n.\\\" between takes teh following args in order\r\n.\\\" $1: value to test\r\n.\\\" $2: center of bucket\r\n.\\\" $3: bucket width\r\n.\\\" $4: variable stem\r\n.\\\" if the test value is in the bucket (between the center +\/- width\/2) \r\n.\\\" the macro increments the variable made from concatenating the stem and\r\n.\\\" the bucket center.\r\ndefine between {\r\n  if ($1 &gt;= $2-($3\/2) &amp;&amp; $1 &lt; $2+($3\/2) ) then {\r\n    $4$2 = $4$2 + 1\r\n  } \r\n}\r\n\r\n.\\\" Copy the test data through between calls to set the globals\r\ncopy \"data\" thru {\r\n  between($1,105,10,tot)\r\n  between($1,115,10,tot)\r\n  between($1,125,10,tot)\r\n  between($1,135,10,tot)\r\n  between($1,145,10,tot)\r\n  between($1,155,10,tot)\r\n  between($1,165,10,tot)\r\n  between($1,175,10,tot)\r\n  between($1,185,10,tot)\r\n  between($1,195,10,tot)\r\n  between($1,205,10,tot)\r\n  between($1,215,10,tot)\r\n  if ($3 == 1) then {\r\n    between($1,105,5,rtot)\r\n    between($1,110,5,rtot)\r\n    between($1,115,5,rtot)\r\n    between($1,120,5,rtot)\r\n    between($1,125,5,rtot)\r\n    between($1,130,5,rtot)\r\n    between($1,135,5,rtot)\r\n    between($1,140,5,rtot)\r\n    between($1,145,5,rtot)\r\n    between($1,150,5,rtot)\r\n    between($1,155,5,rtot)\r\n    between($1,160,5,rtot)\r\n    between($1,165,5,rtot)\r\n    between($1,170,5,rtot)\r\n    between($1,175,5,rtot)\r\n    between($1,180,5,rtot)\r\n    between($1,190,5,rtot)\r\n    between($1,185,5,rtot)\r\n    between($1,195,5,rtot)\r\n    between($1,200,5,rtot)\r\n    between($1,205,5,rtot)\r\n    between($1,210,5,rtot)\r\n    between($1,215,5,rtot)\r\n  }\r\n}\r\n\r\n.\\\" Set up the coordinates and the ticks to match the example\r\ncoord x 100, 220 y 0,8\r\nticks bot in 0.02 down 0.04 from 100 to 220 by 20\r\nticks top in 0.02 from 100 to 220 by 20 \"\"\r\nticks left in 0.02 left 0.08 from 0 to 8\r\nticks right in 0.02 from 0 to 8 \"\"\r\nlabel left \"Number of Members\"\r\nlabel bot \"Weight in Pounds\"\r\nlabel top \"The Boat Race Crew Histograms\" size +2\r\n\r\n.\\\" Draw bars for both kinds of crew<\/pre>\n<pre>bar up 105 ht tot105 wid 10 fillcolor \"blue\"\r\nbar up 115 ht tot115 wid 10 fillcolor \"blue\"\r\nbar up 125 ht tot125 wid 10 fillcolor \"blue\"\r\nbar up 135 ht tot135 wid 10 fillcolor \"blue\"\r\nbar up 145 ht tot145 wid 10 fillcolor \"blue\"\r\nbar up 155 ht tot155 wid 10 fillcolor \"blue\"\r\nbar up 165 ht tot165 wid 10 fillcolor \"blue\"\r\nbar up 175 ht tot175 wid 10 fillcolor \"blue\"\r\nbar up 185 ht tot185 wid 10 fillcolor \"blue\"\r\nbar up 195 ht tot195 wid 10 fillcolor \"blue\"\r\nbar up 205 ht tot205 wid 10 fillcolor \"blue\"\r\nbar up 215 ht tot215 wid 10 fillcolor \"blue\"\r\n\r\n.\\\" Draw bars for rowers\r\nbar up 105 ht rtot105 wid 5 fillcolor \"forestgreen\"\r\nbar up 110 ht rtot110 wid 5 fillcolor \"forestgreen\"\r\nbar up 115 ht rtot115 wid 5 fillcolor \"forestgreen\"\r\nbar up 120 ht rtot120 wid 5 fillcolor \"forestgreen\"\r\nbar up 125 ht rtot125 wid 5 fillcolor \"forestgreen\"\r\nbar up 130 ht rtot130 wid 5 fillcolor \"forestgreen\"\r\nbar up 135 ht rtot135 wid 5 fillcolor \"forestgreen\"\r\nbar up 140 ht rtot140 wid 5 fillcolor \"forestgreen\"\r\nbar up 145 ht rtot145 wid 5 fillcolor \"forestgreen\"\r\nbar up 150 ht rtot150 wid 5 fillcolor \"forestgreen\"\r\nbar up 155 ht rtot155 wid 5 fillcolor \"forestgreen\"\r\nbar up 160 ht rtot160 wid 5 fillcolor \"forestgreen\"\r\nbar up 165 ht rtot165 wid 5 fillcolor \"forestgreen\"\r\nbar up 170 ht rtot170 wid 5 fillcolor \"forestgreen\"\r\nbar up 175 ht rtot175 wid 5 fillcolor \"forestgreen\"\r\nbar up 180 ht rtot180 wid 5 fillcolor \"forestgreen\"\r\nbar up 185 ht rtot185 wid 5 fillcolor \"forestgreen\"\r\nbar up 190 ht rtot190 wid 5 fillcolor \"forestgreen\"\r\nbar up 195 ht rtot195 wid 5 fillcolor \"forestgreen\"\r\nbar up 200 ht rtot200 wid 5 fillcolor \"forestgreen\"\r\nbar up 205 ht rtot205 wid 5 fillcolor \"forestgreen\"\r\nbar up 210 ht rtot210 wid 5 fillcolor \"forestgreen\"\r\nbar up 215 ht rtot215 wid 5 fillcolor \"forestgreen\"\r\n\r\n.\\\" Draw a key (Note that the positions here are in the histogram coordinates)\r\nbar 102, 7.8, 155, 6.5\r\nbar 105, 7.6, 120, 7.2 fillcolor \"blue\"\r\nbar 105, 7.0, 120, 6.6 fillcolor \"forestgreen\"\r\n\"rowers and coxswains\" ljust size -4 at 122, 7.4\r\n\"rowers and coxswains\" ljust size -4 at 122, 6.8\r\n.G2<\/pre>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I know everyone loves it when I talk about arcane typesetting languages, so here&#8217;s a response to a fellow who wanted to replicate the histograms at http:\/\/www.jmillville.com\/project\/learnstats\/ex9.html in grap. &nbsp; Attached is a commented grap\/groff file that draws something like both histograms. I commented the grap to explain what I was up to (comments start [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2657","post","type-post","status-publish","format-standard","hentry","category-general"],"_links":{"self":[{"href":"https:\/\/www.lunabase.org\/~faber\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lunabase.org\/~faber\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lunabase.org\/~faber\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lunabase.org\/~faber\/blog\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lunabase.org\/~faber\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2657"}],"version-history":[{"count":1,"href":"https:\/\/www.lunabase.org\/~faber\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2657\/revisions"}],"predecessor-version":[{"id":2658,"href":"https:\/\/www.lunabase.org\/~faber\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2657\/revisions\/2658"}],"wp:attachment":[{"href":"https:\/\/www.lunabase.org\/~faber\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lunabase.org\/~faber\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lunabase.org\/~faber\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}