{"id":675,"date":"2014-10-23T10:13:44","date_gmt":"2014-10-23T17:13:44","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=675"},"modified":"2014-10-23T10:13:44","modified_gmt":"2014-10-23T17:13:44","slug":"playing-with-the-playwith-package","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2014\/10\/23\/playing-with-the-playwith-package\/","title":{"rendered":"Playing with the \u2018playwith\u2019 package"},"content":{"rendered":"<div class=\"itemhead\">\n<h3>Playing with the \u2018playwith\u2019 package<\/h3>\n<div class=\"chronodata\">23mar10<\/div>\n<\/div>\n<div class=\"itemtext\">\n<p><a href=\"http:\/\/ryouready.files.wordpress.com\/2010\/03\/playwith_demo.png\"><img decoding=\"async\" class=\"alignleft size-medium wp-image-552\" title=\"playwith_demo\" src=\"http:\/\/ryouready.files.wordpress.com\/2010\/03\/playwith_demo.png?w=300&amp;h=269\" alt=\"\" \/><\/a>Abilities of R for creating graphics is great, but one thing I always missed is the possibility of creating interactive plots and being able to look at graphs while changing one ore more parameters. I know that there is <a href=\"http:\/\/www.ggobi.org\/rggobi\/\">rggobi<\/a>, but so far I always ran into problems with flexibility each time I wanted to use it. So I kept on searching until I found<a href=\"http:\/\/code.google.com\/p\/playwith\/\">playwith<\/a> which is \u201can R package, providing a GTK+ graphical user interface for editing and interacting with R plots\u201d as its homepage says. The homepage includes a lot of <a href=\"http:\/\/code.google.com\/p\/playwith\/wiki\/Screenshots\">screenshots<\/a> with code snippets so this post doesn\u2019t intend to give an extensive review about the possibilities of the playwith package to the reader. All I want to do now is present a small application of it.<span id=\"more-528\"><\/span><\/p>\n<p>I had some geospatial data I wanted to visualize. The data was a result of a computer simulation and consisted of a set of geographical coordinates and corresponding frequency values expressed in Hz. The values associated to the coordinates <img decoding=\"async\" class=\"latex\" title=\"(x,y)\" src=\"http:\/\/s0.wp.com\/latex.php?latex=%28x%2Cy%29&amp;bg=ffffff&amp;fg=333333&amp;s=0\" alt=\"(x,y)\" \/>\u00a0 tells us the first eigenfrequency of the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Schumann_resonances\">Earth-ionosphere cavity<\/a>that would be measured at <a href=\"http:\/\/w.ggki.hu\/index.php?id=38&amp;L=1\">Nagycenk Observatory<\/a> in the case of an assumed lightning source at <img decoding=\"async\" class=\"latex\" title=\"(x,y)\" src=\"http:\/\/s0.wp.com\/latex.php?latex=%28x%2Cy%29&amp;bg=ffffff&amp;fg=333333&amp;s=0\" alt=\"(x,y)\" \/> with certain properties.<\/p>\n<p>At first, as always, we need to load some packages.<br \/>\n<code><br \/>\nlibrary(R.basic) # for creating perspective plot<br \/>\nlibrary(playwith) # for creating interactive plot<br \/>\nlibrary(fields) # for plotting a map of the world<\/code><\/p>\n<p>Then, we read in our data (which is available online, so the example must be reproducible):<\/p>\n<p><code><br \/>\nregs &lt;- list(Africa=\"Africa\",Americas=\"Americas\",Asia=\"Asia\")<br \/>\ncols &lt;- c(Africa=\"red\",Americas=\"green\",Asia=\"blue\")<br \/>\nurl &lt;- \"http:\/\/storage.ggki.hu\/~nattomi\/ryouready\/20100303\"<br \/>\nx &lt;- lapply(regs, function(x) {read.table(file.path(url,x),header=TRUE)})<\/code><\/p>\n<p>Before plotting, I determine the range of the plottted values.<br \/>\n<code><br \/>\ndata(world.dat) # data used for plotting a world map<br \/>\nzAxs &lt;- unlist(lapply(x,function(x) x$fnERT1))<br \/>\nr &lt;- range(zAxs)<br \/>\n<\/code><\/p>\n<p>And finally, the interactive plot itself:<br \/>\n<code><br \/>\nplaywith({plot3d(world.dat$x,world.dat$y,lowZ,pch=\".\",<br \/>\nzlim=c(lowZ,upZ),xlab=\"longitude\",<\/code><br \/>\n<code>ylab=\"latitude\",zlab=\"F1 (Hz)\",<br \/>\ntheta=theta,phi=phi,ticktype=\"detailed\")<br \/>\nfor (i in regs) {<br \/>\nd &lt;- x[[i]]<br \/>\npoints3d(d$Dc,d$Hc,d$fnERT1,col=cols[[i]],pch=\".\")<br \/>\n}},<br \/>\nparameters=list(<br \/>\ntheta=seq(0,360,by=5),<br \/>\nphi=seq(0,90,by=5),<br \/>\nlowZ=seq(r[1],r[2],0.5),<br \/>\nupZ=seq(r[2],r[1],-0.5)))<\/code><\/p>\n<p>You should see a window popping up with 4 sliders allowing you to set different paramters of the plot, for example vertical and horizontal rotation. You can already see from the example that the syntax of the <em>playwith<\/em> command is very simple, you specify a set of commands necessary for creating the plot (with possible parameters included such as <em>theta<\/em> in this example) between curly braces then a list specifying values to be looped through for the parameters. What more could I say? If you are a visual type (or your boss is one) then play with <em>playwith<\/em>!<\/p>\n<p><strong>Remark 1<\/strong>: Installing the package <em>R.basic<\/em> goes in a little bit unusual way, see<a href=\"http:\/\/www.braju.com\/R\/\">http:\/\/www.braju.com\/R\/<\/a> for details.<\/p>\n<p><strong>Remark 2<\/strong>: My world map is just a plot of a cloud of points on the plane. It would be nice if the points would be connected accordingly. This can be achieved by using the<em>world()<\/em> command in the <em>fields<\/em> package although I wasn\u2019t able to integrate this into the 3d display. Any suggestions are very welcome. The <em><span class=\"skimlinks-unlinked\">world.dat<\/span><\/em> dataset has an another drawback: it doesn\u2019t include <a href=\"http:\/\/www.openstreetmap.org\/?lat=40.77&amp;lon=11.01&amp;zoom=7&amp;layers=B000FTF\">Corsica and Sardinia<\/a> so this world map is not of too much use for the locals.<\/p>\n<p><a href=\"http:\/\/ryouready.files.wordpress.com\/2010\/03\/playwith.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-546\" title=\"playwith\" src=\"http:\/\/ryouready.files.wordpress.com\/2010\/03\/playwith.png?w=500&amp;h=295\" alt=\"\" width=\"500\" height=\"295\" \/><\/a><\/p>\n<div class=\"wpcnt\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Playing with the \u2018playwith\u2019 package 23mar10 Abilities of R for creating graphics is great, but one thing I always missed is the possibility of creating&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-675","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=675"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/675\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}