<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>R-statistics blog &#187; plot</title>
	<atom:link href="http://www.r-statistics.com/tag/plot/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.r-statistics.com</link>
	<description>Writing about statistics with R, and open source stuff (software, data, community)</description>
	<lastBuildDate>Mon, 30 Jan 2012 07:45:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Visualization of regression coefficients (in R)</title>
		<link>http://www.r-statistics.com/2010/07/visualization-of-regression-coefficients-in-r/</link>
		<comments>http://www.r-statistics.com/2010/07/visualization-of-regression-coefficients-in-r/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 19:46:56 +0000</pubDate>
		<dc:creator>Tal Galili</dc:creator>
				<category><![CDATA[R]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[visualization]]></category>
		<category><![CDATA[coefficients]]></category>
		<category><![CDATA[Coefficients Visualization]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[plot]]></category>
		<category><![CDATA[regression]]></category>
		<category><![CDATA[regression plot]]></category>
		<category><![CDATA[regression Visualization]]></category>

		<guid isPermaLink="false">http://www.r-statistics.com/?p=435</guid>
		<description><![CDATA[Update (07.07.10): The function in this post has a more mature version in the &#8220;arm&#8221; package.  (more details are available at the end of this post.) Update (04.01.12): There is a new package called Coefplot that offers a more general solution for plotting coeffs. (more details are available at the end of this post.) * * * * Imagine [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:right;"><div class="socialize-in-button socialize-in-button-right"><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.r-statistics.com/2010/07/visualization-of-regression-coefficients-in-r/&amp;layout=box_count&amp;show_faces=false&amp;width=50&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px !important; height:65px;" allowTransparency="true"></iframe></div><div class="socialize-in-button socialize-in-button-right"><g:plusone size="tall" href="http://www.r-statistics.com/2010/07/visualization-of-regression-coefficients-in-r/"></g:plusone></div></div><p><strong>Update (07.07.10)</strong>: The function in this post has a more mature version in the &#8220;arm&#8221; package.  <em>(more details are available at the end of this post.)</em></p>
<p><strong>Update (04.01.12)</strong>: There is a new package called <a href="http://cran.r-project.org/web/packages/coefplot/" target="_self">Coefplot</a> that offers a more general solution for plotting coeffs. <em>(more details are available at the end of this post.)</em><br />
* * * *</p>
<p>Imagine you want to give a presentation or report of your latest findings running some sort of regression analysis. How would you do it?</p>
<p>This was exactly the question Wincent Rong-gui HUANG has recently asked <a href="http://r.789695.n4.nabble.com/Visualization-of-coefficients-tt2276010.html#none">on the R mailing list</a>.</p>
<p>One person, Bernd Weiss, responded by linking to the chapter &#8220;<a href="http://tables2graphs.com/doku.php?id=04_regression_coefficients">Plotting Regression Coefficients</a>&#8221; on an interesting online book (I have never heard of before) called &#8220;<a href="http://tables2graphs.com/doku.php">Using Graphs Instead of Tables</a>&#8221; (I should add this link to the <a href="http://www.r-statistics.com/2009/10/free-statistics-e-books-for-download/">free statistics e-books list</a>&#8230;)</p>
<p>Letter in the conversation, <a href="http://statmath.wu.ac.at/~zeileis/">Achim Zeileis</a>, has surprised us (well, me) saying the following</p>
<blockquote><p>I&#8217;ve thought about adding a plot() method for the coeftest() function in the <a href="http://cran.r-project.org/web/packages/lmtest/index.html">&#8220;lmtest&#8221; package</a>. Essentially, it relies on a coef() and a vcov() method being available &#8211; <strong>and that a central limit theorem holds</strong>. For releasing it as a general function in the package the code is still too raw, but maybe it&#8217;s useful for someone on the list. Hence,<strong> I&#8217;ve included it below</strong>.</p></blockquote>
<p>(I allowed myself to add some <strong>bolds</strong> in the text)</p>
<p>So for the convenience of all of us, I uploaded Achim&#8217;s code in a file for easy access. Here is an example of how to use it:</p>

<div class="wp_codebox"><table><tr id="p4353"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p435code3"><pre class="rsplus" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">source</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">&quot;http://www.r-statistics.com/wp-content/uploads/2010/07/coefplot.r.txt&quot;</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">&quot;Mroz&quot;</span>, package <span style="color: #080;">=</span> <span style="color: #ff0000;">&quot;car&quot;</span><span style="color: #080;">&#41;</span>
fm</pre></td></tr></table></div>

<p>Here is the resulting graph:<br />
<a href="http://www.r-statistics.com/wp-content/uploads/2010/07/regression-coefficient-plot.png"><img class="alignright size-full wp-image-437" title="regression coefficient plot" src="http://www.r-statistics.com/wp-content/uploads/2010/07/regression-coefficient-plot.png" alt="" width="550" /></a></p>
<p>I hope Achim will get around to improve the function so he might think it worthy of joining his<a href="http://cran.r-project.org/web/packages/lmtest/index.html">&#8220;lmtest&#8221; package</a>. I am glad he shared his code for the rest of us to have something to work with in the meantime <img src='http://www.r-statistics.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>* * *</p>
<p><strong>Update (07.07.10)</strong>:<br />
Thanks to a comment by David Atkins, I found out there is a more mature version of this function (called <strong>coefplot</strong>) inside the {arm} package. This version offers many features, one of which is the ability to easily stack several confidence intervals one on top of the other.</p>
<p>It works for baysglm, glm, lm, polr objects and a default method is available which takes pre-computed coefficients and associated standard errors from any suitable model.</p>
<p><strong>Example:</strong><br />
(Notice that the Poisson model in comparison with the binomial models does not make much sense, but is enough to illustrate the use of the function)</p>

<div class="wp_codebox"><table><tr id="p4354"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p435code4"><pre class="rsplus" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">&quot;arm&quot;</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">&quot;Mroz&quot;</span>, package <span style="color: #080;">=</span> <span style="color: #ff0000;">&quot;car&quot;</span><span style="color: #080;">&#41;</span>
M1</pre></td></tr></table></div>

<p>(hat tip goes to Allan Engelhardt for help improving the code, and for Achim Zeileis in extending and improving the narration for the example)</p>
<p><strong>Resulting plot </strong></p>
<p><a href="http://www.r-statistics.com/wp-content/uploads/2010/07/coeff-visualization-3.png"><img class="alignright size-full wp-image-471" title="coeff visualization 3" src="http://www.r-statistics.com/wp-content/uploads/2010/07/coeff-visualization-3.png" alt="" width="550" /></a></p>
<p>* * *<br />
Another method worth mentioning is the Nomogram, implemented by Frank Harrell&#8217;a {<a href="http://biostat.mc.vanderbilt.edu/wiki/Main/Rrms">rms} package</a>.</p>
<p>* * *</p>
<p><strong>Update (04.01.12)</strong>:</p>
<p>The package {<a href="http://cran.r-project.org/web/packages/coefplot/" target="_self">Coefplot</a>}, by Jared Lander, plots coefficients from lm and glm models as well as from models generated by RevoScaleR&#8217;s rxLinMod and rxLogit functions.  The package is built on top of ggplot2 graphics, you can see an example for its use <a href="http://blog.revolutionanalytics.com/2012/01/new-package-for-plotting-model-coefficients.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.r-statistics.com/2010/07/visualization-of-regression-coefficients-in-r/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nutritional supplements efficacy score &#8211; Graphing plots of current studies results (using R)</title>
		<link>http://www.r-statistics.com/2010/02/nutritional-supplements-efficacy-score-graphing-plots-of-current-studies-results-using-r/</link>
		<comments>http://www.r-statistics.com/2010/02/nutritional-supplements-efficacy-score-graphing-plots-of-current-studies-results-using-r/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 21:17:07 +0000</pubDate>
		<dc:creator>Tal Galili</dc:creator>
				<category><![CDATA[R]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[visualization]]></category>
		<category><![CDATA[allergy research supplements]]></category>
		<category><![CDATA[amino acids supplements]]></category>
		<category><![CDATA[balloon]]></category>
		<category><![CDATA[balloon plot]]></category>
		<category><![CDATA[balloon plot R]]></category>
		<category><![CDATA[barplot]]></category>
		<category><![CDATA[benefits supplements]]></category>
		<category><![CDATA[capsules supplements]]></category>
		<category><![CDATA[dietary research]]></category>
		<category><![CDATA[effects supplements]]></category>
		<category><![CDATA[fibromyalgia research]]></category>
		<category><![CDATA[glucosamine research]]></category>
		<category><![CDATA[glucosamine supplements]]></category>
		<category><![CDATA[google excel]]></category>
		<category><![CDATA[google spread sheet]]></category>
		<category><![CDATA[google spreadsheet]]></category>
		<category><![CDATA[green tea research]]></category>
		<category><![CDATA[hair loss research]]></category>
		<category><![CDATA[herbal research]]></category>
		<category><![CDATA[herbs research]]></category>
		<category><![CDATA[herbs supplements]]></category>
		<category><![CDATA[immune system supplements]]></category>
		<category><![CDATA[liquid research]]></category>
		<category><![CDATA[liquid supplements]]></category>
		<category><![CDATA[magnesium research]]></category>
		<category><![CDATA[mineral research]]></category>
		<category><![CDATA[minerals research]]></category>
		<category><![CDATA[natural health supplements]]></category>
		<category><![CDATA[natural research]]></category>
		<category><![CDATA[nutritional research]]></category>
		<category><![CDATA[plot]]></category>
		<category><![CDATA[pregnancy supplements]]></category>
		<category><![CDATA[R code]]></category>
		<category><![CDATA[side effects supplements]]></category>
		<category><![CDATA[sports nutrition supplements]]></category>
		<category><![CDATA[supplement research]]></category>
		<category><![CDATA[supplements body building]]></category>
		<category><![CDATA[supplements bodybuilding]]></category>
		<category><![CDATA[supplements dietary]]></category>
		<category><![CDATA[supplements foods]]></category>
		<category><![CDATA[supplements herbal]]></category>
		<category><![CDATA[supplements mineral]]></category>
		<category><![CDATA[supplements minerals]]></category>
		<category><![CDATA[supplements nutritional]]></category>
		<category><![CDATA[supplements products]]></category>
		<category><![CDATA[supplements protein]]></category>
		<category><![CDATA[supplements research]]></category>
		<category><![CDATA[take supplements]]></category>
		<category><![CDATA[taking supplements]]></category>
		<category><![CDATA[thyroid research]]></category>
		<category><![CDATA[vitamin b supplements]]></category>
		<category><![CDATA[vitamin c research]]></category>
		<category><![CDATA[vitamin c supplements]]></category>
		<category><![CDATA[vitamin d research]]></category>
		<category><![CDATA[vitamins discount]]></category>
		<category><![CDATA[vitamins minerals supplements]]></category>
		<category><![CDATA[vitamins research]]></category>
		<category><![CDATA[weight loss research]]></category>

		<guid isPermaLink="false">http://www.r-statistics.com/?p=171</guid>
		<description><![CDATA[In this post I showcase a nice bar-plot and a balloon-plot listing recommended Nutritional supplements , according to how much evidence exists for thier benefits, scroll down to see it(and click here for the data behind it) * * * * The gorgeous blog &#8220;Information Is Beautiful&#8221; recently publish an eye candy post showing a [...]]]></description>
			<content:encoded><![CDATA[<div class="socialize-in-content" style="float:right;"><div class="socialize-in-button socialize-in-button-right"><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.r-statistics.com/2010/02/nutritional-supplements-efficacy-score-graphing-plots-of-current-studies-results-using-r/&amp;layout=box_count&amp;show_faces=false&amp;width=50&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px !important; height:65px;" allowTransparency="true"></iframe></div><div class="socialize-in-button socialize-in-button-right"><g:plusone size="tall" href="http://www.r-statistics.com/2010/02/nutritional-supplements-efficacy-score-graphing-plots-of-current-studies-results-using-r/"></g:plusone></div></div><p>In this post I showcase a nice <strong>bar-plot and a balloon-plot listing recommended Nutritional supplements</strong> , according to how much evidence exists for thier benefits, scroll down to see it(and <a href="http://spreadsheets.google.com/ccc?key=0Aqe2P9sYhZ2ndFRKaU1FaWVvOEJiV2NwZ0JHck12X1E&amp;hl=en_GB">click here</a> for the data behind it)<br />
*  *  *  *<br />
The gorgeous blog <a href="http://www.informationisbeautiful.net/">&#8220;Information Is Beautiful&#8221;</a> recently publish an <a href="http://www.informationisbeautiful.net/play/snake-oil-supplements/">eye candy post</a> showing a “balloon race” image (see a static version of the image <a href="http://www.informationisbeautiful.net/visualizations/snake-oil-supplements/">here</a>) illustrating how much evidence exists for the benefits of various Nutritional supplements (such as: green tea, vitamins, herbs, pills and so on) . The higher the bubble in the Y axis <del datetime="2010-03-06T11:34:54+00:00">score (e.g: the bubble size)</del> for the supplement the greater the evidence there is for its effectiveness (But only for the conditions listed along side the supplement).</p>
<p>There are two reasons this should be of interest to us:</p>
<ol>
<li>This shows a fun plot, that R currently doesn&#8217;t know how to do (at least I wasn&#8217;t able to find an implementation for it). So if anyone thinks of an easy way for making one &#8211; please let me know.</li>
<li>The data for the graph is openly (and freely) provided to all of us on <a href="http://spreadsheets.google.com/ccc?key=0Aqe2P9sYhZ2ndFRKaU1FaWVvOEJiV2NwZ0JHck12X1E&amp;hl=en_GB">this Google Doc</a>.</li>
</ol>
<p>The advantage of having the data on a google doc means that we can see when the data will be updated. But more then that, it means we can easily extract the data into R and have our way with it  (Thanks to <a href="http://blog.revolution-computing.com/2009/09/how-to-use-a-google-spreadsheet-as-data-in-r.html">David Smith&#8217;s post </a>on the subject)</p>
<p>For example, I was wondering what are ALL of the top recommended Nutritional supplements, an answer that is not trivial to get from the plot that was in the <a href="http://www.informationisbeautiful.net/play/snake-oil-supplements/">original post</a>.</p>
<p>In this post I will supply two plots that present the data: A barplot (that in retrospect didn&#8217;t prove to be good enough) and a balloon-plot for a table (that seems to me to be much better).</p>
<p><strong>Barplot</strong><br />
(You can <strong>click the image to enlarge</strong> it)<br />
<a href="http://www.r-statistics.com/wp-content/uploads/2010/02/Nutritional-supplements-efficacy.png"><img class="alignnone size-full wp-image-172" title="Nutritional supplements efficacy" src="http://www.r-statistics.com/wp-content/uploads/2010/02/Nutritional-supplements-efficacy.png" alt="" width="550" /></a></p>
<p>The R code to produce the barplot of Nutritional supplements efficacy score (by evidence for its effectiveness on the listed condition).</p>

<div class="wp_codebox"><table><tr id="p1717"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p171code7"><pre class="rsplus" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># loading the data</span>
supplements.<span style="">data</span>.0 <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">read.<span style="">csv</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">&quot;http://spreadsheets.google.com/pub?key=0Aqe2P9sYhZ2ndFRKaU1FaWVvOEJiV2NwZ0JHck12X1E&amp;output=csv&quot;</span><span style="color: #080;">&#41;</span>
supplements.<span style="">data</span> <span style="color: #080;">&lt;-</span> supplements.<span style="">data</span>.0<span style="color: #080;">&#91;</span>supplements.<span style="">data</span>.0<span style="color: #080;">&#91;</span>,<span style="color: #ff0000;">2</span><span style="color: #080;">&#93;</span> <span style="color: #080;">&gt;</span><span style="color: #ff0000;">2</span>,<span style="color: #080;">&#93;</span> <span style="color: #228B22;"># let's only look at &quot;good&quot; supplements</span>
supplements.<span style="">data</span> <span style="color: #080;">&lt;-</span> supplements.<span style="">data</span><span style="color: #080;">&#91;</span><span style="color: #080;">!</span><span style="color: #0000FF; font-weight: bold;">is.<span style="">na</span></span><span style="color: #080;">&#40;</span>supplements.<span style="">data</span><span style="color: #080;">&#91;</span>,<span style="color: #ff0000;">2</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>,<span style="color: #080;">&#93;</span> <span style="color: #228B22;"># and we don't want any missing data</span>
&nbsp;
supplement.<span style="">score</span> <span style="color: #080;">&lt;-</span> supplements.<span style="">data</span><span style="color: #080;">&#91;</span>, <span style="color: #ff0000;">2</span><span style="color: #080;">&#93;</span>
ss <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">order</span><span style="color: #080;">&#40;</span>supplement.<span style="">score</span>, decreasing  <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">F</span><span style="color: #080;">&#41;</span>	<span style="color: #228B22;"># sort our data</span>
supplement.<span style="">score</span> <span style="color: #080;">&lt;-</span> supplement.<span style="">score</span><span style="color: #080;">&#91;</span>ss<span style="color: #080;">&#93;</span>
supplement.<span style="">name</span> <span style="color: #080;">&lt;-</span> supplements.<span style="">data</span><span style="color: #080;">&#91;</span>ss, <span style="color: #ff0000;">1</span><span style="color: #080;">&#93;</span>
supplement.<span style="">benefits</span> <span style="color: #080;">&lt;-</span> supplements.<span style="">data</span><span style="color: #080;">&#91;</span>ss, <span style="color: #ff0000;">4</span><span style="color: #080;">&#93;</span>
supplement.<span style="">score</span>.<span style="">col</span> <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">factor</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">as.<span style="">character</span></span><span style="color: #080;">&#40;</span>supplement.<span style="">score</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
	<span style="color: #0000FF; font-weight: bold;">levels</span><span style="color: #080;">&#40;</span>supplement.<span style="">score</span>.<span style="">col</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&lt;-</span>  <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">&quot;red&quot;</span>, <span style="color: #ff0000;">&quot;orange&quot;</span>, <span style="color: #ff0000;">&quot;blue&quot;</span>, <span style="color: #ff0000;">&quot;dark green&quot;</span><span style="color: #080;">&#41;</span>
	supplement.<span style="">score</span>.<span style="">col</span> <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">as.<span style="">character</span></span><span style="color: #080;">&#40;</span>supplement.<span style="">score</span>.<span style="">col</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;"># mar: c(bottom, left, top, right) The default is c(5, 4, 4, 2) + 0.1.</span>
<span style="color: #0000FF; font-weight: bold;">par</span><span style="color: #080;">&#40;</span>mar <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">5</span>,<span style="color: #ff0000;">9</span>,<span style="color: #ff0000;">4</span>,<span style="color: #ff0000;">13</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>	<span style="color: #228B22;"># taking care of the plot margins</span>
bar.<span style="">y</span> <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">barplot</span><span style="color: #080;">&#40;</span>supplement.<span style="">score</span>, names.<span style="">arg</span><span style="color: #080;">=</span> supplement.<span style="">name</span>, las <span style="color: #080;">=</span> <span style="color: #ff0000;">1</span>, horiz <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">T</span>, <span style="color: #0000FF; font-weight: bold;">col</span> <span style="color: #080;">=</span> supplement.<span style="">score</span>.<span style="">col</span>, xlim <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">0</span>,<span style="color: #ff0000;">6.2</span><span style="color: #080;">&#41;</span>,
				main <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">&quot;Nutritional supplements efficacy score&quot;</span>,<span style="color: #ff0000;">&quot;(by evidence for its effectiveness on the listed condition)&quot;</span>, <span style="color: #ff0000;">&quot;(2010)&quot;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">axis</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">4</span>, <span style="color: #0000FF; font-weight: bold;">labels</span> <span style="color: #080;">=</span> supplement.<span style="">benefits</span>, at <span style="color: #080;">=</span> bar.<span style="">y</span>, las <span style="color: #080;">=</span> <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span> <span style="color: #228B22;"># Add right axis</span>
<span style="color: #0000FF; font-weight: bold;">abline</span><span style="color: #080;">&#40;</span>h <span style="color: #080;">=</span> bar.<span style="">y</span>, <span style="color: #0000FF; font-weight: bold;">col</span> <span style="color: #080;">=</span> supplement.<span style="">score</span>.<span style="">col</span> , lty <span style="color: #080;">=</span> <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span> <span style="color: #228B22;"># add some lines so to easily follow each bar</span></pre></td></tr></table></div>

<p>Also, the nice things is that if the guys at Information Is Beautiful will update there data, we could easily run the code and see the updated list of recommended supplements.</p>
<p><strong>Balloon plot</strong><br />
So after some web surfing I came around an implementation of a balloon plot in R (Thanks to <a href="http://addictedtor.free.fr/graphiques/graphcode.php?graph=60">R graph gallery</a>)<br />
There where two problems with using the command out of the box. The first one was that the colors where non informative (easily fixed), the second one was that the X labels where overlapping one another. Since there is no &#8220;las&#8221; parameter in the function, I just opened the function up, found where this was plotted and changed it manually (a bit messy, but that&#8217;s what you have to do sometimes&#8230;)</p>
<p>Here are the result (you can click the image for a larger image):</p>
<p><a href="http://www.r-statistics.com/wp-content/uploads/2010/02/balloonplot.png"><img src="http://www.r-statistics.com/wp-content/uploads/2010/02/balloonplot.png" alt="" title="balloonplot" width="550" class="alignnone size-full wp-image-199" /></a></p>
<p>And here is The R code to produce the Balloon plot of Nutritional supplements efficacy score (by evidence for its effectiveness on the listed condition).<br />
 (it&#8217;s just the copy of the function with a tiny bit of editing in line 146, and then using it)</p>
<p><span id="more-171"></span></p>

<div class="wp_codebox"><table><tr id="p1718"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code" id="p171code8"><pre class="rsplus" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">require</span><span style="color: #080;">&#40;</span>colorspace<span style="color: #080;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">require</span><span style="color: #080;">&#40;</span>gplots<span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;"># I was able to find the function by using</span>
<span style="color: #228B22;"># methods(balloonplot)[1]</span>
<span style="color: #228B22;"># This command: getAnywhere(&quot;balloonplot.default&quot;) # Wouldn't work...</span>
balloonplot2 <span style="color: #080;">&lt;-</span> gplots<span style="color: #080;">:::</span><span style="">balloonplot</span>.<span style="">default</span> <span style="color: #228B22;"># This one works :)</span>
&nbsp;
<span style="color: #228B22;"># now run:</span>
<span style="color: #0000FF; font-weight: bold;">fix</span><span style="color: #080;">&#40;</span>balloonplot2<span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># search for </span>
<span style="color: #228B22;"># y &lt;- ny + 0.75 + (nlabels.x - i + 0.5) * colmar</span>
<span style="color: #228B22;"># And add beneath it the following line:</span>
<span style="color: #228B22;"># y &lt;- rep(y, dim(xlabs)[1]) - c(0,.5,1)</span>
&nbsp;
supplement.<span style="">benefits</span> <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">tolower</span><span style="color: #080;">&#40;</span>supplement.<span style="">benefits</span> <span style="color: #080;">&#41;</span>
supplement.<span style="">name</span>		<span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">tolower</span><span style="color: #080;">&#40;</span>supplement.<span style="">name</span><span style="color: #080;">&#41;</span>
&nbsp;
balloonplot2<span style="color: #080;">&#40;</span> supplement.<span style="">name</span>,supplement.<span style="">benefits</span>, supplement.<span style="">score</span>, xlab <span style="color: #080;">=</span><span style="color: #ff0000;">&quot;supplement&quot;</span>, ylab<span style="color: #080;">=</span><span style="color: #ff0000;">&quot;Benefit&quot;</span>,
			show.<span style="">margins</span><span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">F</span>, dotsize <span style="color: #080;">=</span> <span style="color: #ff0000;">15</span>,fun<span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span><span style="color: #0000FF; font-weight: bold;">max</span><span style="color: #080;">&#40;</span>x,na.<span style="">rm</span><span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">T</span><span style="color: #080;">&#41;</span>,			
			rowmar <span style="color: #080;">=</span> <span style="color: #ff0000;">7</span>,
			colmar <span style="color: #080;">=</span> <span style="color: #ff0000;">7</span>,
			dotcolor <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">rev</span><span style="color: #080;">&#40;</span>heat_hcl<span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">max</span><span style="color: #080;">&#40;</span> supplement.<span style="">score</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#91;</span> supplement.<span style="">score</span><span style="color: #080;">-</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#93;</span>,
			main <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">&quot;Balloon plot of&quot;</span>, <span style="color: #ff0000;">&quot;Nutritional supplements efficacy score&quot;</span>,<span style="color: #ff0000;">&quot;(by evidence for its effectiveness on the listed condition)&quot;</span>, <span style="color: #ff0000;">&quot;(2010)&quot;</span><span style="color: #080;">&#41;</span>,
			<span style="color: #0000FF; font-weight: bold;">sub</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">&quot;Published on www.r-statistics.com&quot;</span><span style="color: #080;">&#41;</span>				
			<span style="color: #080;">&#41;</span></pre></td></tr></table></div>

<p>Got any good ideas of how else to plot the data? let me know in the comments <img src='http://www.r-statistics.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.r-statistics.com/2010/02/nutritional-supplements-efficacy-score-graphing-plots-of-current-studies-results-using-r/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>

