{"id":851,"date":"2015-04-07T10:43:19","date_gmt":"2015-04-07T17:43:19","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=851"},"modified":"2015-04-07T10:43:19","modified_gmt":"2015-04-07T17:43:19","slug":"how-to-format-plots-for-publication-using-ggplot2","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2015\/04\/07\/how-to-format-plots-for-publication-using-ggplot2\/","title":{"rendered":"How to format plots for publication using ggplot2"},"content":{"rendered":"<p><strong><em>The following is the code from a presentation made by Rosemary Hartman to the <a href=\"http:\/\/www.noamross.net\/davis-r-users-group.html\">Davis R Users\u2019 Group<\/a>. I\u2019ve run the code through the <code>spin<\/code> function in <code>knitr<\/code> to produce this post. Download the script to walk through<a href=\"https:\/\/gist.github.com\/noamross\/7576436\">here<\/a>.<\/em><\/strong><\/p>\n<p>First, make your plot. I am going to use the data already in R about sleep habits of different animals. It\u2019s the same one Noam used for <a href=\"http:\/\/www.noamross.net\/blog\/2012\/10\/5\/ggplot-introduction.html\">his intro to ggplot.<\/a><\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\"><span class=\"kw\">library<\/span>(ggplot2)\n<span class=\"kw\">str<\/span>(msleep)<\/code><\/pre>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">## 'data.frame':    83 obs. of  11 variables:\n##  $ name        : chr  \"Cheetah\" \"Owl monkey\" \"Mountain beaver\" \"Greater short-tailed shrew\" ...\n##  $ genus       : chr  \"Acinonyx\" \"Aotus\" \"Aplodontia\" \"Blarina\" ...\n##  $ vore        : Factor w\/ 4 levels \"carni\",\"herbi\",..: 1 4 2 4 2 2 1 NA 1 2 ...\n##  $ order       : chr  \"Carnivora\" \"Primates\" \"Rodentia\" \"Soricomorpha\" ...\n##  $ conservation: Factor w\/ 7 levels \"\",\"cd\",\"domesticated\",..: 5 NA 6 5 3 NA 7 NA 3 5 ...\n##  $ sleep_total : num  12.1 17 14.4 14.9 4 14.4 8.7 7 10.1 3 ...\n##  $ sleep_rem   : num  NA 1.8 2.4 2.3 0.7 2.2 1.4 NA 2.9 NA ...\n##  $ sleep_cycle : num  NA NA NA 0.133 0.667 ...\n##  $ awake       : num  11.9 7 9.6 9.1 20 9.6 15.3 17 13.9 21 ...\n##  $ brainwt     : num  NA 0.0155 NA 0.00029 0.423 NA NA NA 0.07 0.0982 ...\n##  $ bodywt      : num  50 0.48 1.35 0.019 600 ...<\/code><\/pre>\n<p>Let\u2019s say we have written a groundbreaking paper on the relationship between body size and sleep time. Therefore, we want to present a plot of the log of body weight by the total sleep time<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot = <span class=\"kw\">ggplot<\/span>(<span class=\"dt\">data =<\/span> msleep, <span class=\"kw\">aes<\/span>(<span class=\"dt\">x =<\/span> <span class=\"kw\">log<\/span>(bodywt), <span class=\"dt\">y =<\/span> sleep_total)) + <span class=\"kw\">geom_point<\/span>(<span class=\"kw\">aes<\/span>(<span class=\"dt\">color =<\/span> vore))\nsleepplot<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-2.png\" alt=\"\" \/><\/figure>\n<p>We made a beautiful model of this relationship<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">slp = <span class=\"kw\">lm<\/span>(sleep_total ~ <span class=\"kw\">log<\/span>(bodywt), <span class=\"dt\">data =<\/span> msleep)\n<span class=\"kw\">summary<\/span>(slp)<\/code><\/pre>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">## \n## Call:\n## lm(formula = sleep_total ~ log(bodywt), data = msleep)\n## \n## Residuals:\n##    Min     1Q Median     3Q    Max \n## -6.499 -2.567 -0.168  2.047 10.193 \n## \n## Coefficients:\n##             Estimate Std. Error t value Pr(&gt;|t|)    \n## (Intercept)   11.089      0.418   26.54   &lt;2e-16 ***\n## log(bodywt)   -0.777      0.125   -6.22    2e-08 ***\n## ---\n## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n## \n## Residual standard error: 3.68 on 81 degrees of freedom\n## Multiple R-squared:  0.323,  Adjusted R-squared:  0.315 \n## F-statistic: 38.7 on 1 and 81 DF,  p-value: 2.05e-08<\/code><\/pre>\n<p>Let\u2019s put the model on the plot<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot = sleepplot + <span class=\"kw\">geom_abline<\/span>(<span class=\"dt\">intercept =<\/span> <span class=\"kw\">coef<\/span>(slp)[<span class=\"dv\">1<\/span>], <span class=\"dt\">slope =<\/span> <span class=\"kw\">coef<\/span>(slp)[<span class=\"dv\">2<\/span>])\nsleepplot<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-4.png\" alt=\"\" \/><\/figure>\n<p>It\u2019s beautiful! I love it! Unfortunately, you want to submit to Science (you might as well aim high), and this is what they say about figures:<a class=\"uri\" href=\"http:\/\/www.sciencemag.org\/site\/feature\/contribinfo\/prep\/prep_subfigs.xhtml\">http:\/\/www.sciencemag.org\/site\/feature\/contribinfo\/prep\/prep_subfigs.xhtml<\/a><\/p>\n<p>So we have several problems:<\/p>\n<ul>\n<li>gray background<\/li>\n<li>Poor labels (need units, capital letters, larger font on axes)<\/li>\n<li>Poor legend<\/li>\n<li>Poor color scheme (avoid red and green together, more contrast needed)<\/li>\n<li>Not correct file format or resolution (want a PDF with at least 600dpi)<\/li>\n<\/ul>\n<p>First make the labels a little more useful.<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot = sleepplot + <span class=\"kw\">labs<\/span>(<span class=\"dt\">x =<\/span> <span class=\"st\">\"Log body weight (Kg)\"<\/span>, <span class=\"dt\">y =<\/span> <span class=\"st\">\"Time asleep (hrs\/day)\"<\/span>)\nsleepplot<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-5.png\" alt=\"\" \/><\/figure>\n<p>Now let\u2019s fix the legend. You would think you do this with some sort of \u201clegend\u201d command, but <em>no<\/em>, what you are looking for is \u201cscale\u201d.<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot + <span class=\"kw\">scale_color_discrete<\/span>(<span class=\"dt\">name =<\/span> <span class=\"st\">\"Functional<\/span><span class=\"ch\">\\n<\/span><span class=\"st\"> feeding group\"<\/span>, <span class=\"dt\">labels =<\/span> <span class=\"kw\">c<\/span>(<span class=\"st\">\"carnivore\"<\/span>, \n    <span class=\"st\">\"herbivore\"<\/span>, <span class=\"st\">\"insectivore\"<\/span>, <span class=\"st\">\"omnivore\"<\/span>))<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-6.png\" alt=\"\" \/><\/figure>\n<p>If you haven\u2019t figured it out yet, putting \u201c<code>\\n<\/code>\u201d in a text string gives you a line break. It took me WAY to long to discover that.<\/p>\n<p><code>ggplot<\/code> automatically gives you evenly spaced hues for color variations, but this is not necessarily the best way to get a good contrasting color scheme. You may want to try <code>scale_color_brewer<\/code> for better contrasts. See <a class=\"uri\" href=\"http:\/\/colorbrewer2.org\/\">http:\/\/colorbrewer2.org<\/a> for more information.<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot + <span class=\"kw\">scale_color_brewer<\/span>(<span class=\"dt\">name =<\/span> <span class=\"st\">\"Functional <\/span><span class=\"ch\">\\n<\/span><span class=\"st\"> feeding group\"<\/span>, <span class=\"dt\">labels =<\/span> <span class=\"kw\">c<\/span>(<span class=\"st\">\"carnivore\"<\/span>, \n    <span class=\"st\">\"herbivore\"<\/span>, <span class=\"st\">\"insectivore\"<\/span>, <span class=\"st\">\"omnivore\"<\/span>), <span class=\"dt\">type =<\/span> <span class=\"st\">\"qual\"<\/span>, <span class=\"dt\">palette =<\/span> <span class=\"dv\">1<\/span>)<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-7.png\" alt=\"\" \/><\/figure>\n<p>Oh, crap! Color figures cost an extra $700 on top of the normal page charges! Let\u2019s try something else:<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot2 = <span class=\"kw\">ggplot<\/span>(<span class=\"dt\">data =<\/span> msleep, <span class=\"kw\">aes<\/span>(<span class=\"dt\">x =<\/span> <span class=\"kw\">log<\/span>(bodywt), <span class=\"dt\">y =<\/span> sleep_total)) + \n  <span class=\"kw\">geom_point<\/span>(<span class=\"kw\">aes<\/span>(<span class=\"dt\">shape=<\/span>vore), <span class=\"dt\">size=<\/span><span class=\"dv\">3<\/span>) + <span class=\"co\">#' This time we will vary the feeding groups by shapes instead of colors<\/span>\n  <span class=\"kw\">geom_abline<\/span>(<span class=\"dt\">intercept=<\/span><span class=\"kw\">coef<\/span>(slp)[<span class=\"dv\">1<\/span>], <span class=\"dt\">slope=<\/span><span class=\"kw\">coef<\/span>(slp)[<span class=\"dv\">2<\/span>])\n  sleepplot2<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-8.png\" alt=\"\" \/><\/figure>\n<p>Now to fix the labels and legend again:<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot2 = sleepplot2 + <span class=\"kw\">labs<\/span>(<span class=\"dt\">x =<\/span> <span class=\"st\">\"Log body weight (Kg)\"<\/span>, <span class=\"dt\">y =<\/span> <span class=\"st\">\"Time asleep (hrs\/day)\"<\/span>) + \n    <span class=\"co\">#' we will use scale_shape_discrete instead of scale_color_discrete<\/span>\n<span class=\"kw\">scale_shape_discrete<\/span>(<span class=\"dt\">name =<\/span> <span class=\"st\">\"Functional <\/span><span class=\"ch\">\\n<\/span><span class=\"st\"> feeding group\"<\/span>, <span class=\"dt\">labels =<\/span> <span class=\"kw\">c<\/span>(<span class=\"st\">\"carnivore\"<\/span>, \n    <span class=\"st\">\"herbivore\"<\/span>, <span class=\"st\">\"insectivore\"<\/span>, <span class=\"st\">\"omnivore\"<\/span>))\nsleepplot2<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-9.png\" alt=\"\" \/><\/figure>\n<p>Now, let\u2019s work on how the plot looks overall.<\/p>\n<p>ggplot uses \u201cthemes\u201d to adjust plot appearence without changes the actual presentation of the data.<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot2 + <span class=\"kw\">theme_bw<\/span>(<span class=\"dt\">base_size =<\/span> <span class=\"dv\">12<\/span>, <span class=\"dt\">base_family =<\/span> <span class=\"st\">\"Helvetica\"<\/span>)<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-10.png\" alt=\"\" \/><\/figure>\n<p><code>theme_bw()<\/code> will get rid of the background, and gives you options to change the font. Science recomends Helvetica, wich happens to be R\u2019s default, but we will specify it here anyway.<\/p>\n<p>Check out the other fonts out here:<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">??postscriptFonts<\/code><\/pre>\n<p>For even more fonts, see the <code>extrafont<\/code> package.<\/p>\n<p>Other pre-set themes can change the look of your plot<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot2 + <span class=\"kw\">theme_minimal<\/span>()<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-111.png\" alt=\"\" \/><\/figure>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot2 + <span class=\"kw\">theme_classic<\/span>()<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-112.png\" alt=\"\" \/><\/figure>\n<p>For more themes,<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\"><span class=\"kw\">library<\/span>(ggthemes)<\/code><\/pre>\n<p>If you want to publish in the Wall Street Journal\u2026<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot2 + <span class=\"kw\">theme_wsj<\/span>()<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-13.png\" alt=\"\" \/><\/figure>\n<p>But we want to publish in Science, not the Wall Street Journal, so let\u2019s get back to our black and white theme.<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot2 = sleepplot2 + <span class=\"kw\">theme_bw<\/span>(<span class=\"dt\">base_size =<\/span> <span class=\"dv\">12<\/span>, <span class=\"dt\">base_family =<\/span> <span class=\"st\">\"Helvetica\"<\/span>)\nsleepplot2<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-14.png\" alt=\"\" \/><\/figure>\n<p>You can\u2019t really see the gridlines with the <code>bw<\/code> theme, so we are going to tweak the pre-set theme using the<code>theme<\/code> function. <code>theme<\/code> allows you to do all kinds of stuff involved with how the plot looks.<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">?theme<\/code><\/pre>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot2 + \n  <span class=\"co\">#increase size of gridlines<\/span>\n  <span class=\"kw\">theme<\/span>(<span class=\"dt\">panel.grid.major =<\/span> <span class=\"kw\">element_line<\/span>(<span class=\"dt\">size =<\/span> .<span class=\"dv\">5<\/span>, <span class=\"dt\">color =<\/span> <span class=\"st\">\"grey\"<\/span>),\n  <span class=\"co\">#increase size of axis lines<\/span>\n  <span class=\"dt\">axis.line =<\/span> <span class=\"kw\">element_line<\/span>(<span class=\"dt\">size=<\/span>.<span class=\"dv\">7<\/span>, <span class=\"dt\">color =<\/span> <span class=\"st\">\"black\"<\/span>),\n  <span class=\"co\">#Adjust legend position to maximize space, use a vector of proportion<\/span>\n  <span class=\"co\">#across the plot and up the plot where you want the legend. <\/span>\n  <span class=\"co\">#You can also use \"left\", \"right\", \"top\", \"bottom\", for legends on t<\/span>\n  <span class=\"co\">#he side of the plot<\/span>\n  <span class=\"dt\">legend.position =<\/span> <span class=\"kw\">c<\/span>(.<span class=\"dv\">85<\/span>,.<span class=\"dv\">7<\/span>),\n  <span class=\"co\">#increase the font size<\/span>\n  <span class=\"dt\">text =<\/span> <span class=\"kw\">element_text<\/span>(<span class=\"dt\">size=<\/span><span class=\"dv\">14<\/span>)) <\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-15.png\" alt=\"\" \/><\/figure>\n<p>You can save this theme for later use<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">science_theme = <span class=\"kw\">theme<\/span>(<span class=\"dt\">panel.grid.major =<\/span> <span class=\"kw\">element_line<\/span>(<span class=\"dt\">size =<\/span> <span class=\"fl\">0.5<\/span>, <span class=\"dt\">color =<\/span> <span class=\"st\">\"grey\"<\/span>), \n    <span class=\"dt\">axis.line =<\/span> <span class=\"kw\">element_line<\/span>(<span class=\"dt\">size =<\/span> <span class=\"fl\">0.7<\/span>, <span class=\"dt\">color =<\/span> <span class=\"st\">\"black\"<\/span>), <span class=\"dt\">legend.position =<\/span> <span class=\"kw\">c<\/span>(<span class=\"fl\">0.85<\/span>, \n        <span class=\"fl\">0.7<\/span>), <span class=\"dt\">text =<\/span> <span class=\"kw\">element_text<\/span>(<span class=\"dt\">size =<\/span> <span class=\"dv\">14<\/span>))\nsleepplot2 = sleepplot2 + science_theme\nsleepplot2<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-16.png\" alt=\"\" \/><\/figure>\n<p>That looks pretty good. Now we need to get it exported properly. The instructions say the figure should be sized to fit in one or two columns (2.3 or 4.6 inches), so we want them to look good at that resolution.<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\"><span class=\"kw\">pdf<\/span>(<span class=\"dt\">file =<\/span> <span class=\"st\">\"sleepplot.pdf\"<\/span>, <span class=\"dt\">width=<\/span> <span class=\"dv\">6<\/span>, <span class=\"dt\">height =<\/span> <span class=\"dv\">4<\/span>, <span class=\"co\">#' see how it looks at this size<\/span>\n    <span class=\"dt\">useDingbats=<\/span>F) <span class=\"co\">#I have had trouble when uploading figures with digbats before, so I don't use them<\/span>\nsleepplot2 <span class=\"co\">#print our plot<\/span>\n<span class=\"kw\">dev.off<\/span>() <span class=\"co\">#stop making pdfs<\/span><\/code><\/pre>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">## pdf \n##   2<\/code><\/pre>\n<h4 id=\"a-few-other-tricks-to-improve-the-look-of-your-plots\">A few other tricks to improve the look of your plots:<\/h4>\n<p>Let\u2019s say we are grouping things by categories instead of a regression<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepcat = <span class=\"kw\">ggplot<\/span>(msleep, <span class=\"kw\">aes<\/span>(<span class=\"dt\">x =<\/span> vore, <span class=\"dt\">y =<\/span> sleep_total, <span class=\"dt\">color =<\/span> conservation))\nsleepcat + <span class=\"kw\">geom_point<\/span>()<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-18.png\" alt=\"\" \/><\/figure>\n<p>It\u2019s hard to see what\u2019s going on there, so we can jitter the points to make them more visible.<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepcat + <span class=\"kw\">geom_point<\/span>(<span class=\"dt\">position =<\/span> <span class=\"kw\">position_jitter<\/span>(<span class=\"dt\">w =<\/span> <span class=\"fl\">0.1<\/span>))<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-19.png\" alt=\"\" \/><\/figure>\n<p>Maybe this would be better with averages and error bars instead of every point:<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\"><span class=\"kw\">library<\/span>(plyr)\nmsleepave = <span class=\"kw\">ddply<\/span>(msleep, .(vore, conservation), summarize, <span class=\"dt\">meansleep =<\/span> <span class=\"kw\">mean<\/span>(sleep_total), \n    <span class=\"dt\">sdsleep =<\/span> <span class=\"kw\">sd<\/span>(sleep_total)\/<span class=\"kw\">sqrt<\/span>(<span class=\"dv\">22<\/span>))\nsleepmean = <span class=\"kw\">ggplot<\/span>(msleepave, <span class=\"kw\">aes<\/span>(<span class=\"dt\">x =<\/span> vore, <span class=\"dt\">y =<\/span> meansleep, <span class=\"dt\">color =<\/span> conservation))<\/code><\/pre>\n<p>Plot it with means and error bars +\/- 1 stadard deviation<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepmean + <span class=\"kw\">geom_point<\/span>() + <span class=\"kw\">geom_errorbar<\/span>(<span class=\"kw\">aes<\/span>(<span class=\"dt\">ymax =<\/span> meansleep + sdsleep, <span class=\"dt\">ymin =<\/span> meansleep + \n    sdsleep), <span class=\"dt\">width =<\/span> <span class=\"fl\">0.2<\/span>)<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-21.png\" alt=\"\" \/><\/figure>\n<p>Spread them out, but in an orderly fashion this time, with position_dodge rather than jitter<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepmean + <span class=\"kw\">geom_point<\/span>(<span class=\"dt\">position =<\/span> <span class=\"kw\">position_dodge<\/span>(<span class=\"dt\">width =<\/span> <span class=\"fl\">0.5<\/span>, <span class=\"dt\">height =<\/span> <span class=\"dv\">0<\/span>), <span class=\"dt\">size =<\/span> <span class=\"dv\">2<\/span>) + \n    <span class=\"kw\">geom_errorbar<\/span>(<span class=\"kw\">aes<\/span>(<span class=\"dt\">ymax =<\/span> meansleep + sdsleep, <span class=\"dt\">ymin =<\/span> meansleep - sdsleep), \n        <span class=\"dt\">position =<\/span> <span class=\"kw\">position_dodge<\/span>(<span class=\"dt\">width =<\/span> <span class=\"fl\">0.5<\/span>, <span class=\"dt\">height =<\/span> <span class=\"dv\">0<\/span>), <span class=\"dt\">width =<\/span> <span class=\"fl\">0.5<\/span>)<\/code><\/pre>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">## ymax not defined: adjusting position using y instead<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-22.png\" alt=\"\" \/><\/figure>\n<p>Note that dodging the points gives the conservation status in the same order for each feeding type category. A little more organized.<\/p>\n<h4 id=\"some-other-things-you-might-want-to-do-with-formatting\">Some other things you might want to do with formatting:<\/h4>\n<p>Add annotation to the plot<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot2 + <span class=\"kw\">annotate<\/span>(<span class=\"st\">\"text\"<\/span>, <span class=\"dt\">label =<\/span> <span class=\"st\">\"R2 = 0.999\"<\/span>, <span class=\"dt\">x =<\/span> -<span class=\"dv\">4<\/span>, <span class=\"dt\">y =<\/span> <span class=\"dv\">17<\/span>)<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-23.png\" alt=\"\" \/><\/figure>\n<p>Let\u2019s put that annotation in italics<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">sleepplot2 + <span class=\"kw\">annotate<\/span>(<span class=\"st\">\"text\"<\/span>, <span class=\"dt\">label =<\/span> <span class=\"st\">\"R2 = 0.999\"<\/span>, <span class=\"dt\">x =<\/span> -<span class=\"dv\">4<\/span>, <span class=\"dt\">y =<\/span> <span class=\"dv\">17<\/span>, <span class=\"dt\">fontface =<\/span> <span class=\"dv\">3<\/span>)<\/code><\/pre>\n<figure><img decoding=\"async\" src=\"http:\/\/dl.dropbox.com\/u\/3356641\/blogstuff\/roseplot-24.png\" alt=\"\" \/><\/figure>\n<p>NOW. Let\u2019s put half that annotation in italics, the other half plain, then insert five greek characters and rotate it 90 degrees!<\/p>\n<p>OR we can beat our head against a wall until it explodes and export our plot into an actual graphics program.<\/p>\n<p>Not everything has to be done in R. \u2018SVG\u2019 files are vector graphic files that can be easily edited in the FREE GUI-based program <a href=\"http:\/\/inkscape.org\/\">Inkscape<\/a>. Make and SVG and you can edit it by hand for final tweaks. Inkscape can also edit and export PDFs.<\/p>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\"><span class=\"kw\">svg<\/span>(<span class=\"dt\">filename =<\/span> <span class=\"st\">\"sleepplot.svg\"<\/span>, <span class=\"dt\">width =<\/span> <span class=\"dv\">6<\/span>, <span class=\"dt\">height =<\/span> <span class=\"dv\">4<\/span>)\nsleepplot2\n<span class=\"kw\">dev.off<\/span>()<\/code><\/pre>\n<pre class=\"sourceCode r\"><code class=\"sourceCode r\">## pdf \n##   2<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following is the code from a presentation made by Rosemary Hartman to the Davis R Users\u2019 Group. I\u2019ve run the code through the spin&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-851","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/851","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=851"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/851\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}