{"id":87,"date":"2019-09-09T14:04:57","date_gmt":"2019-09-09T14:04:57","guid":{"rendered":"http:\/\/www.ben-parker.co.uk\/?p=87"},"modified":"2019-09-09T14:04:57","modified_gmt":"2019-09-09T14:04:57","slug":"playing-with-the-tidyverse","status":"publish","type":"post","link":"http:\/\/www.ben-parker.co.uk\/?p=87","title":{"rendered":"Playing with the tidyverse"},"content":{"rendered":"<p>Although I&#8217;ve been an R user for some time, and have taught a variety of courses in R for statistics, I&#8217;ve never been a great user of the data science elements of R; I had a little spare time over the summer and have been trying to catch up with the tidyverse, mostly by starting with <a href=\"https:\/\/r4ds.had.co.nz\/data-visualisation.html\">Hadley Wickham&#8217;s excellent book, R for Data Science<\/a><\/p>\n<p>Whilst I&#8217;m not sure I&#8217;ll ever be a data scientist, I find the power of this quite amazing, especially compared to how I used to teach graphing in R. It does take a little more time, but filtering large data sets in R, and graphing becomes a breeze.<\/p>\n<p>I&#8217;ve been working for some time on a statistical model for test cricket, which seems quite promising. I&#8217;ve used the <a href=\"https:\/\/cran.r-project.org\/web\/packages\/yorkr\/index.html\">yorkr package<\/a>\u00a0, modified a little for test cricket, in order to download every ball of test cricket from the <a href=\"https:\/\/cricsheet.org\">excellent cricsheet website.<\/a>\u00a0There&#8217;s some 415 published test matches, and after some data issues I&#8217;ve so far successfully converted 399 of them.<\/p>\n<p>Anyway, to demonstrate how easy it is to get interesting results using the tidyverse, here&#8217;s some data on the number of runs scored and overs faced for each test wicket.<\/p>\n<p><a href=\"http:\/\/www.ben-parker.co.uk\/wp-content\/uploads\/2019\/09\/overs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-90 size-full\" src=\"http:\/\/www.ben-parker.co.uk\/wp-content\/uploads\/2019\/09\/overs.png\" alt=\"\" width=\"1200\" height=\"847\" srcset=\"http:\/\/www.ben-parker.co.uk\/wp-content\/uploads\/2019\/09\/overs.png 1200w, http:\/\/www.ben-parker.co.uk\/wp-content\/uploads\/2019\/09\/overs-300x212.png 300w, http:\/\/www.ben-parker.co.uk\/wp-content\/uploads\/2019\/09\/overs-768x542.png 768w, http:\/\/www.ben-parker.co.uk\/wp-content\/uploads\/2019\/09\/overs-1024x723.png 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><!--more--><\/p>\n<p>Code used to generate graphs:<\/p>\n<p><code><br \/>\n&gt; allTests<br \/>\n# A tibble: 13,084 x 9<br \/>\n# Groups: date, team, team1, team2, venue, innings [1,473]<br \/>\ndate team team1 team2 venue innings innWicket oversPerWicket runsPerWicket<br \/>\n&lt;date&gt; &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;<br \/>\n1 2016-11-06 Sri Lanka Zimbabwe Sri Lanka Harare Sports Club 1st 1 14.7 62<br \/>\n2 2016-11-06 Sri Lanka Zimbabwe Sri Lanka Harare Sports Club 1st 2 1.83 4<br \/>\n3 2016-11-06 Sri Lanka Zimbabwe Sri Lanka Harare Sports Club 1st 3 7.67 18<br \/>\n4 2016-11-06 Sri Lanka Zimbabwe Sri Lanka Harare Sports Club 1st 4 3.83 28<br \/>\n5 2016-11-06 Sri Lanka Zimbabwe Sri Lanka Harare Sports Club 1st 5 50.5 143<br \/>\n6 2016-11-06 Sri Lanka Zimbabwe Sri Lanka Harare Sports Club 1st 6 26.5 87<br \/>\n7 2016-11-06 Sri Lanka Zimbabwe Sri Lanka Harare Sports Club 1st 7 11.7 54<br \/>\n8 2016-11-06 Sri Lanka Zimbabwe Sri Lanka Harare Sports Club 1st 8 18.5 75<br \/>\n9 2016-11-06 Sri Lanka Zimbabwe Sri Lanka Harare Sports Club 1st 9 0.333 0<br \/>\n10 2016-11-06 Sri Lanka Zimbabwe Sri Lanka Harare Sports Club 1st 10 8.67 33<br \/>\n# ... with 13,074 more rows<br \/>\n&gt; ggplot(data = tempData) +<br \/>\ngeom_point(mapping = aes(y = oversPerWicket, x = runsPerWicket, colour=factor(innings))) +<br \/>\nfacet_wrap(~ innWicket, nrow = 5) +<br \/>\nylab(\"Overs Faced\") + xlab(\"Runs\") +<br \/>\nlabs(title=\"Runs and over faced per wicket\\nSelected Test Matches 2008-2017\",color=\"Innings\")<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Although I&#8217;ve been an R user for some time, and have taught a variety of courses in R for statistics, I&#8217;ve never been a great user of the data science elements of R; I had a little spare time over the summer and have been trying to catch up with the tidyverse, mostly by starting [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-87","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.ben-parker.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/87","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ben-parker.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ben-parker.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ben-parker.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ben-parker.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=87"}],"version-history":[{"count":3,"href":"http:\/\/www.ben-parker.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/87\/revisions"}],"predecessor-version":[{"id":92,"href":"http:\/\/www.ben-parker.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/87\/revisions\/92"}],"wp:attachment":[{"href":"http:\/\/www.ben-parker.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=87"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ben-parker.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=87"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ben-parker.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=87"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}