<?xml version="1.0" encoding="UTF-8" ?>
<!-- RSS generated by PHPBoost on Sun, 08 Mar 2026 11:59:00 +0100 -->

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Easy Guides]]></title>
		<atom:link href="https://www.sthda.com/english/syndication/rss/wiki/43" rel="self" type="application/rss+xml"/>
		<link>https://www.sthda.com</link>
		<description><![CDATA[Last articles of the category: R Base Graphs]]></description>
		<copyright>(C) 2005-2026 PHPBoost</copyright>
		<language>en</language>
		<generator>PHPBoost</generator>
		
		
		<item>
			<title><![CDATA[R Base Graphs]]></title>
			<link>https://www.sthda.com/english/wiki/r-base-graphs</link>
			<guid>https://www.sthda.com/english/wiki/r-base-graphs</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">
<p><br/></p>
<p>Previously, we described the <a href="https://www.sthda.com/english/english/wiki/r-basics-quick-and-easy">essentials of R programming</a> and provided quick start guides for <a href="https://www.sthda.com/english/english/wiki/importing-data-into-r">importing data</a> into <strong>R</strong>.</p>
<br/>
<div class="block">
This chapter contains articles describring how to visualize data using <strong>R base graphs</strong>.
</div>
<p><br/></p>
<div id="how-this-chapter-is-organized" class="section level1">
<h1>How this chapter is organized?</h1>
<br/>
<div class="block">
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/creating-and-saving-graphs-r-base-graphs">Creating and Saving Graphs in R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/generic-plot-types-in-r-software">Generic plot types in R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plots-r-base-graphs">Scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plot-matrices-r-base-graphs">Scatter Plot Matrices</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/box-plots-r-base-graphs">Box Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/strip-charts-1-d-scatter-plots-r-base-graphs">Strip Charts: 1-D scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/bar-plots-r-base-graphs">Bar Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/line-plots-r-base-graphs">Line Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/pie-charts-r-base-graphs">Pie Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/histogram-and-density-plots-r-base-graphs">Histogram and Density Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/qq-plots-quantile-quantile-plots-r-base-graphs">QQ-plots: Quantile-Quantile plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/dot-charts-r-base-graphs">Dot Charts</a></li>
<li><p><a href="https://www.sthda.com/english/english/wiki/plot-group-means-and-confidence-intervals-r-base-graphs">Plot Group Means and Confidence Intervals</a></p></li>
<li><a href="https://www.sthda.com/english/english/wiki/graphical-parameters">R base graphical Parameters</a></li>
</ul>
</div>
<p><br/></p>
<hr/>
</div>
<div id="creating-and-saving-graphs" class="section level1">
<h1>Creating and saving graphs</h1>
<ul>
<li>Creating graphs</li>
<li>Saving graphs</li>
<li>File formats for exporting plots</li>
</ul>
<div class="figure">
<img src="https://www.sthda.com/english/sthda/RDoc/images/create-save-plots-r.png" alt="create and save plots" /><p class="caption">create and save plots</p>
</div>
<p><span class="success">Read more: —> <a href="https://www.sthda.com/english/english/wiki/creating-and-saving-graphs-r-base-graphs">Creating and Saving Graphs in R</a>.</span></p>
</div>
<div id="generic-plot-types-in-r" class="section level1">
<h1>Generic plot types in R</h1>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-plot-types-1.png" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-plot-types-2.png" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-plot-types-3.png" width="144" /></p>
<p><span class="success">Read more: —> <a href="https://www.sthda.com/english/english/wiki/generic-plot-types-in-r-software">Generic plot types in R</a>.</span></p>
</div>
<div id="scatter-plots" class="section level1">
<h1>Scatter plots</h1>
<ul>
<li>R base scatter plot: plot()</li>
<li>Enhanced scatter plots: car::scatterplot()</li>
<li>3D scatter plots</li>
</ul>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-scatterplot-car-package-1.png" width="384" /></p>
<p><span class="success">Read more: —> <a href="https://www.sthda.com/english/english/wiki/scatter-plots-r-base-graphs">Scatter Plots</a>.</span></p>
</div>
<div id="scatter-plot-matrices" class="section level1">
<h1>Scatter plot matrices</h1>
<ul>
<li>R base scatter plot matrices: pairs()</li>
<li>Use the R package psych</li>
</ul>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-scatter-plot-matrices-1.png" width="528" /></p>
<p><span class="success">Read more —> <a href="https://www.sthda.com/english/english/wiki/scatter-plot-matrices-r-base-graphs">Scatter Plot Matrices</a>.</span></p>
</div>
<div id="box-plots" class="section level1">
<h1>Box plots</h1>
<ul>
<li>R base box plots: boxplot()</li>
<li>Box plot with the number of observations: gplots::boxplot2()</li>
</ul>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-box-plot-change-color-1.png" width="288" /></p>
<p><span class="success">Read more —> <a href="https://www.sthda.com/english/english/wiki/box-plots-r-base-graphs">Box Plots</a>.</span></p>
</div>
<div id="strip-charts-1-d-scatter-plots" class="section level1">
<h1>Strip Charts: 1-D scatter Plots</h1>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-stripchart-customized-1.png" width="384" /></p>
<p><span class="success">Read more —> <a href="https://www.sthda.com/english/english/wiki/strip-charts-1-d-scatter-plots-r-base-graphs">Strip Charts: 1-D scatter Plots</a>.</span></p>
</div>
<div id="bar-plots" class="section level1">
<h1>Bar plots</h1>
<ul>
<li>Basic bar plots
<ul>
<li>Change group names</li>
<li>Change color</li>
<li>Change main title and axis labels</li>
</ul></li>
<li>Stacked bar plots</li>
<li>Grouped bar plots</li>
</ul>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-bar-plot-change-color-1.png" width="259.2" /></p>
<p><span class="success">Read more —> <a href="https://www.sthda.com/english/english/wiki/bar-plots-r-base-graphs">Bar Plots</a>.</span></p>
</div>
<div id="line-plots" class="section level1">
<h1>Line plots</h1>
<ul>
<li>R base functions: plot() and lines()</li>
<li>Basic line plots</li>
<li>Plots with multiple lines</li>
</ul>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-line-plots-1.png" width="288" /></p>
<p><span class="success">Read more —> <a href="https://www.sthda.com/english/english/wiki/line-plots-r-base-graphs">Line Plots</a>.</span></p>
</div>
<div id="pie-charts" class="section level1">
<h1>Pie charts</h1>
<ul>
<li>Create basic pie charts: pie()</li>
<li>Create 3D pie charts: plotix::pie3D()</li>
</ul>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-pie-1.png" width="384" /></p>
<p><span class="success">Read more —> <a href="https://www.sthda.com/english/english/wiki/pie-charts-r-base-graphs">Pie Charts</a>.</span></p>
</div>
<div id="histogram-and-density-plots" class="section level1">
<h1>Histogram and density plots</h1>
<ul>
<li>Create histogram plots: hist()</li>
<li>Create density plots: density()</li>
</ul>
<pre><code>## [1] 48.96467 56.38715 60.42221 43.27151 57.14562 57.53028</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-histogram-density-1.png" width="384" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-histogram-density-2.png" width="384" /></p>
<p><span class="success">Read more —> <a href="https://www.sthda.com/english/english/wiki/histogram-and-density-plots-r-base-graphs">Histogram and Density Plots</a>.</span></p>
</div>
<div id="qq-plots-quantile-quantile-plots" class="section level1">
<h1>QQ-plots: Quantile-Quantile plots</h1>
<p>Use <strong>qqPlot</strong>() [in <strong>car</strong> package]:</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-qqPlot-car-package-1.png" width="384" /></p>
<p><span class="success">Read more —> <a href="https://www.sthda.com/english/english/wiki/qq-plots-quantile-quantile-plots-r-base-graphs">QQ-plots: Quantile-Quantile plots</a>.</span></p>
</div>
<div id="dot-charts" class="section level1">
<h1>Dot charts</h1>
<ul>
<li>R base function: dotchart()</li>
<li>Dot chart of one numeric vector</li>
<li>Dot chart of a matrix</li>
</ul>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-dot-chart-1.png" width="384" /></p>
<p><span class="success">Read more —> <a href="https://www.sthda.com/english/english/wiki/dot-charts-r-base-graphs">Dot charts</a>.</span></p>
</div>
<div id="plot-group-means-and-confidence-intervals" class="section level1">
<h1>Plot group means and confidence intervals</h1>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-base-graphs-plot-means-1.png" width="384" /></p>
<p><span class="success">Read more —> <a href="https://www.sthda.com/english/english/wiki/plot-group-means-and-confidence-intervals-r-base-graphs">Plot Group Means and Confidence Intervals</a>.</span></p>
</div>
<div id="r-base-graphical-parameters" class="section level1">
<h1>R base graphical parameters</h1>
<ul>
<li>Add and customize titles</li>
<li>Add legends</li>
<li>Add texts</li>
<li>Add straight lines</li>
<li>Add an axis to a plot</li>
<li>Change axis scale : minimum, maximum and log scale</li>
<li>Customize tick mark labels</li>
<li>Change plotting symbols</li>
<li>Change line types</li>
<li>Change colors</li>
</ul>
<p><span class="success">Read more —> <a href="https://www.sthda.com/english/english/wiki/graphical-parameters">R base graphical Parameters</a>.</span></p>
</div>
<div id="see-also" class="section level1">
<h1>See also</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/lattice-graphs">Lattice Graphs</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/ggplot2-essentials">ggplot2 Graphs</a></li>
</ul>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.2.4). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('#rdoc h1').addClass('wiki_paragraph1');
    jQuery('#rdoc h2').addClass('wiki_paragraph2');
    jQuery('#rdoc h3').addClass('wiki_paragraph3');
    jQuery('#rdoc h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->


<!-- END HTML -->]]></description>
			<pubDate>Mon, 26 Sep 2016 06:55:40 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[QQ-plots: Quantile-Quantile plots - R Base Graphs]]></title>
			<link>https://www.sthda.com/english/wiki/qq-plots-quantile-quantile-plots-r-base-graphs</link>
			<guid>https://www.sthda.com/english/wiki/qq-plots-quantile-quantile-plots-r-base-graphs</guid>
			<description><![CDATA[<!-- START HTML -->

            
  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#pleleminary-tasks">Pleleminary tasks</a></li>
<li><a href="#example-data">Example data</a></li>
<li><a href="#create-qq-plots">Create QQ plots</a></li>
<li><a href="#related-articles">Related articles</a></li>
<li><a href="#see-also">See also</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>Previously, we described the <a href="https://www.sthda.com/english/english/wiki/r-basics-quick-and-easy">essentials of R programming</a> and provided quick start guides for <a href="https://www.sthda.com/english/english/wiki/importing-data-into-r">importing data</a> into <strong>R</strong>.</p>
<br/>
<div class="block">
Here, we’ll describe how to create <strong>quantile-quantile</strong> plots in R. <strong>QQ plot</strong> (or quantile-quantile plot) draws the correlation between a given sample and the normal distribution. A 45-degree reference line is also plotted. QQ plots are used to visually check the normality of the data.
</div>
<p><br/></p>
<div id="pleleminary-tasks" class="section level1">
<h1>Pleleminary tasks</h1>
<ol style="list-style-type: decimal">
<li><p><strong>Launch RStudio</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/running-rstudio-and-setting-up-your-working-directory-easy-r-programming">Running RStudio and setting up your working directory</a></p></li>
<li><p><strong>Prepare your data</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/best-practices-in-preparing-data-files-for-importing-into-r">Best practices for preparing your data</a> and save it in an external .txt tab or .csv files</p></li>
<li><p><strong>Import your data</strong> into <strong>R</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/fast-reading-of-data-from-txt-csv-files-into-r-readr-package">Fast reading of data from txt|csv files into R: readr package</a>.</p></li>
</ol>
</div>
<div id="example-data" class="section level1">
<h1>Example data</h1>
<p>Here, we’ll use the built-in R data set named <a href="https://www.sthda.com/english/english/wiki/r-built-in-data-sets#toothgrowth">ToothGrowth</a>.</p>
<pre class="r"><code># Store the data in the variable my_data
my_data <- ToothGrowth</code></pre>
</div>
<div id="create-qq-plots" class="section level1">
<h1>Create QQ plots</h1>
<p>The R base functions <strong>qqnorm</strong>() and <strong>qqplot</strong>() can be used to produce quantile-quantile plots:</p>
<ul>
<li><strong>qqnorm</strong>(): produces a normal QQ plot of the variable</li>
<li><strong>qqline</strong>(): adds a reference line</li>
</ul>
<pre class="r"><code>qqnorm(my_data$len, pch = 1, frame = FALSE)
qqline(my_data$len, col = "steelblue", lwd = 2)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/qq-plots-qq-plot-1.png" width="384" /></p>
<p>It’s also possible to use the function <strong>qqPlot</strong>() [in <strong>car</strong> package]:</p>
<pre class="r"><code>library("car")
qqPlot(my_data$len)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/qq-plots-qqPlot-car-package-1.png" width="384" /></p>
<p><span class="success">As all the points fall approximately along this reference line, we can assume normality.</span></p>
</div>
<div id="related-articles" class="section level1">
<h1>Related articles</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/creating-and-saving-graphs-r-base-graphs">Creating and Saving Graphs in R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plots-r-base-graphs">Scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plot-matrices-r-base-graphs">Scatter Plot Matrices</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/box-plots-r-base-graphs">Box Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/strip-charts-1-d-scatter-plots-r-base-graphs">Strip Charts: 1-D scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/bar-plots-r-base-graphs">Bar Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/line-plots-r-base-graphs">Line Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/pie-charts-r-base-graphs">Pie Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/dot-charts-r-base-graphs">Dot Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/plot-group-means-and-confidence-intervals-r-base-graphs">Plot Group Means and Confidence Intervals</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/graphical-parameters">Graphical Parameters</a></li>
</ul>
</div>
<div id="see-also" class="section level1">
<h1>See also</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/lattice-graphs">Lattice Graphs</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/ggplot2-essentials">ggplot2 Graphs</a></li>
</ul>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.2.4). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('#rdoc h1').addClass('wiki_paragraph1');
    jQuery('#rdoc h2').addClass('wiki_paragraph2');
    jQuery('#rdoc h3').addClass('wiki_paragraph3');
    jQuery('#rdoc h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->



<!-- END HTML -->]]></description>
			<pubDate>Sun, 25 Sep 2016 21:26:25 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Plot Group Means and Confidence Intervals - R Base Graphs]]></title>
			<link>https://www.sthda.com/english/wiki/plot-group-means-and-confidence-intervals-r-base-graphs</link>
			<guid>https://www.sthda.com/english/wiki/plot-group-means-and-confidence-intervals-r-base-graphs</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#pleleminary-tasks">Pleleminary tasks</a></li>
<li><a href="#data">Data</a></li>
<li><a href="#plot-group-means">Plot group means</a></li>
<li><a href="#related-articles">Related articles</a></li>
<li><a href="#see-also">See also</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>Previously, we described the <a href="https://www.sthda.com/english/english/wiki/r-basics-quick-and-easy">essentials of R programming</a> and provided quick start guides for <a href="https://www.sthda.com/english/english/wiki/importing-data-into-r">importing data</a> into <strong>R</strong>.</p>
<br/>
<div class="block">
Here, we’ll describe how to create <strong>mean plots</strong> with <strong>confidence intervals</strong> in R.
</div>
<p><br/></p>
<div id="pleleminary-tasks" class="section level1">
<h1>Pleleminary tasks</h1>
<ol style="list-style-type: decimal">
<li><p><strong>Launch RStudio</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/running-rstudio-and-setting-up-your-working-directory-easy-r-programming">Running RStudio and setting up your working directory</a></p></li>
<li><p><strong>Prepare your data</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/best-practices-in-preparing-data-files-for-importing-into-r">Best practices for preparing your data</a> and save it in an external .txt tab or .csv files</p></li>
<li><p><strong>Import your data</strong> into <strong>R</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/fast-reading-of-data-from-txt-csv-files-into-r-readr-package">Fast reading of data from txt|csv files into R: readr package</a>.</p></li>
</ol>
<p><span class="success">Here, we’ll use the <a href="https://www.sthda.com/english/english/wiki/r-built-in-data-sets">R built-in ToothGrowth data set</a>.</span></p>
</div>
<div id="data" class="section level1">
<h1>Data</h1>
<pre class="r"><code>head(ToothGrowth)</code></pre>
<pre><code>##    len supp dose
## 1  4.2   VC  0.5
## 2 11.5   VC  0.5
## 3  7.3   VC  0.5
## 4  5.8   VC  0.5
## 5  6.4   VC  0.5
## 6 10.0   VC  0.5</code></pre>
</div>
<div id="plot-group-means" class="section level1">
<h1>Plot group means</h1>
<p>The function <strong>plotmeans</strong>() [in <strong>gplots</strong> package] can be used.</p>
<pre class="r"><code>library(gplots)
# Plot the mean of teeth length by dose groups
plotmeans(len ~ dose, data = ToothGrowth, frame = FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/plot-group-means-plot-means-1.png" title="" alt="" width="384" /></p>
<pre class="r"><code># Add mean labels (mean.labels = TRUE)
# Remove line connection (connect = FALSE)
plotmeans(len ~ dose, data = ToothGrowth, frame = FALSE,
          mean.labels = TRUE, connect = FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/plot-group-means-plot-means-2.png" title="" alt="" width="384" /></p>
</div>
<div id="related-articles" class="section level1">
<h1>Related articles</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/creating-and-saving-graphs-r-base-graphs">Creating and Saving Graphs in R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plots-r-base-graphs">Scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plot-matrices-r-base-graphs">Scatter Plot Matrices</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/box-plots-r-base-graphs">Box Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/strip-charts-1-d-scatter-plots-r-base-graphs">Strip Charts: 1-D scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/bar-plots-r-base-graphs">Bar Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/line-plots-r-base-graphs">Line Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/pie-charts-r-base-graphs">Pie Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/histogram-and-density-plots-r-base-graphs">Histogram and Density Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/dot-charts-r-base-graphs">Dot Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/graphical-parameters">Graphical Parameters</a></li>
</ul>
</div>
<div id="see-also" class="section level1">
<h1>See also</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/lattice-graphs">Lattice Graphs</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/ggplot2-essentials">ggplot2 Graphs</a></li>
</ul>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.2.4). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->



<!-- END HTML -->]]></description>
			<pubDate>Fri, 06 May 2016 07:17:35 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Dot Charts - R Base Graphs]]></title>
			<link>https://www.sthda.com/english/wiki/dot-charts-r-base-graphs</link>
			<guid>https://www.sthda.com/english/wiki/dot-charts-r-base-graphs</guid>
			<description><![CDATA[<!-- START HTML -->

            
  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#pleleminary-tasks">Pleleminary tasks</a></li>
<li><a href="#data">Data</a></li>
<li><a href="#r-base-function-dotchart">R base function: dotchart()</a></li>
<li><a href="#dot-chart-of-one-numeric-vector">Dot chart of one numeric vector</a></li>
<li><a href="#dot-chart-of-a-matrix">Dot chart of a matrix</a></li>
<li><a href="#related-articles">Related articles</a></li>
<li><a href="#see-also">See also</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>Previously, we described the <a href="https://www.sthda.com/english/english/wiki/r-basics-quick-and-easy">essentials of R programming</a> and provided quick start guides for <a href="https://www.sthda.com/english/english/wiki/importing-data-into-r">importing data</a> into <strong>R</strong>.</p>
<br/>
<div class="block">
Here, we’ll describe how to draw a Cleveland <strong>dot plot</strong> in R.
</div>
<p><br/></p>
<div id="pleleminary-tasks" class="section level1">
<h1>Pleleminary tasks</h1>
<ol style="list-style-type: decimal">
<li><p><strong>Launch RStudio</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/running-rstudio-and-setting-up-your-working-directory-easy-r-programming">Running RStudio and setting up your working directory</a></p></li>
<li><p><strong>Prepare your data</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/best-practices-in-preparing-data-files-for-importing-into-r">Best practices for preparing your data</a> and save it in an external .txt tab or .csv files</p></li>
<li><p><strong>Import your data</strong> into <strong>R</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/fast-reading-of-data-from-txt-csv-files-into-r-readr-package">Fast reading of data from txt|csv files into R: readr package</a>.</p></li>
</ol>
<p><span class="success">Here, we’ll use the <a href="https://www.sthda.com/english/english/wiki/r-built-in-data-sets#mtcars-motor-trend-car-road-tests">R built-in mtcars data set</a>.</span></p>
</div>
<div id="data" class="section level1">
<h1>Data</h1>
<p>We’ll use <em>mtcars</em> data sets. We start by ordering the data set according to mpg variable.</p>
<pre class="r"><code>mtcars <- mtcars[order(mtcars$mpg), ]</code></pre>
</div>
<div id="r-base-function-dotchart" class="section level1">
<h1>R base function: dotchart()</h1>
<p>The function <strong>dotchart</strong>() is used to draw a cleveland dot plot.</p>
<pre class="r"><code>dotchart(x, labels = NULL, groups = NULL, 
         gcolor = par("fg"), color = par("fg"))</code></pre>
<br/>
<div class="block">
<ul>
<li><strong>x</strong>: numeric vector or matrix</li>
<li><strong>labels</strong>: a vector of labels for each point.</li>
<li><strong>groups</strong>: a grouping variable indicating how the elements of x are grouped.</li>
<li><strong>gcolor</strong>: color to be used for group labels and values.</li>
<li><strong>color</strong>: the color(s) to be used for points and labels.</li>
</ul>
</div>
<p><br/></p>
</div>
<div id="dot-chart-of-one-numeric-vector" class="section level1">
<h1>Dot chart of one numeric vector</h1>
<pre class="r"><code># Dot chart of a single numeric vector
dotchart(mtcars$mpg, labels = row.names(mtcars),
         cex = 0.6, xlab = "mpg")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/dot-charts-dot-chart-1.png" title="" alt="" width="384" /></p>
<pre class="r"><code># Plot and color by groups cyl
grps <- as.factor(mtcars$cyl)
my_cols <- c("#999999", "#E69F00", "#56B4E9")
dotchart(mtcars$mpg, labels = row.names(mtcars),
         groups = grps, gcolor = my_cols,
         color = my_cols[grps],
         cex = 0.6,  pch = 19, xlab = "mpg")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/dot-charts-dot-chart-2.png" title="" alt="" width="384" /></p>
</div>
<div id="dot-chart-of-a-matrix" class="section level1">
<h1>Dot chart of a matrix</h1>
<pre class="r"><code>dotchart(VADeaths, cex = 0.6,
         main = "Death Rates in Virginia - 1940")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/dot-charts-dot-chart-matrix-1.png" title="" alt="" width="384" /></p>
</div>
<div id="related-articles" class="section level1">
<h1>Related articles</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/creating-and-saving-graphs-r-base-graphs">Creating and Saving Graphs in R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plots-r-base-graphs">Scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plot-matrices-r-base-graphs">Scatter Plot Matrices</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/box-plots-r-base-graphs">Box Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/strip-charts-1-d-scatter-plots-r-base-graphs">Strip Charts: 1-D scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/bar-plots-r-base-graphs">Bar Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/line-plots-r-base-graphs">Line Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/pie-charts-r-base-graphs">Pie Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/histogram-and-density-plots-r-base-graphs">Histogram and Density Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/plot-group-means-and-confidence-intervals-r-base-graphs">Plot Group Means and Confidence Intervals</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/graphical-parameters">Graphical Parameters</a></li>
</ul>
</div>
<div id="see-also" class="section level1">
<h1>See also</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/lattice-graphs">Lattice Graphs</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/ggplot2-essentials">ggplot2 Graphs</a></li>
</ul>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.2.4). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->


<!-- END HTML -->]]></description>
			<pubDate>Fri, 06 May 2016 07:13:24 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Histogram and Density Plots - R Base Graphs]]></title>
			<link>https://www.sthda.com/english/wiki/histogram-and-density-plots-r-base-graphs</link>
			<guid>https://www.sthda.com/english/wiki/histogram-and-density-plots-r-base-graphs</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#pleleminary-tasks">Pleleminary tasks</a></li>
<li><a href="#create-some-data">Create some data</a></li>
<li><a href="#create-histogram-plots-hist">Create histogram plots: hist()</a></li>
<li><a href="#create-density-plots-density">Create density plots: density()</a></li>
<li><a href="#related-articles">Related articles</a></li>
<li><a href="#see-also">See also</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>Previously, we described the <a href="https://www.sthda.com/english/english/wiki/r-basics-quick-and-easy">essentials of R programming</a> and provided quick start guides for <a href="https://www.sthda.com/english/english/wiki/importing-data-into-r">importing data</a> into <strong>R</strong>.</p>
<br/>
<div class="block">
Here, we’ll describe how to create <strong>histogram</strong> and <strong>density plots</strong> in R.
</div>
<p><br/></p>
<div id="pleleminary-tasks" class="section level1">
<h1>Pleleminary tasks</h1>
<ol style="list-style-type: decimal">
<li><p><strong>Launch RStudio</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/running-rstudio-and-setting-up-your-working-directory-easy-r-programming">Running RStudio and setting up your working directory</a></p></li>
<li><p><strong>Prepare your data</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/best-practices-in-preparing-data-files-for-importing-into-r">Best practices for preparing your data</a> and save it in an external .txt tab or .csv files</p></li>
<li><p><strong>Import your data</strong> into <strong>R</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/fast-reading-of-data-from-txt-csv-files-into-r-readr-package">Fast reading of data from txt|csv files into R: readr package</a>.</p></li>
</ol>
</div>
<div id="create-some-data" class="section level1">
<h1>Create some data</h1>
<p>The data set contains the value of weight by sex for 200 individuals.</p>
<pre class="r"><code>set.seed(1234)
x <- c(rnorm(200, mean=55, sd=5),
     rnorm(200, mean=65, sd=5))
head(x)</code></pre>
<pre><code>## [1] 48.96467 56.38715 60.42221 43.27151 57.14562 57.53028</code></pre>
</div>
<div id="create-histogram-plots-hist" class="section level1">
<h1>Create histogram plots: hist()</h1>
<ul>
<li>A histogram can be created using the function <strong>hist</strong>(), which simplified format is as follow:</li>
</ul>
<pre class="r"><code>hist(x, breaks = "Sturges")</code></pre>
<br/>
<div class="block">
<ul>
<li><strong>x</strong>: a numeric vector</li>
<li><strong>breaks</strong>: breakpoints between histogram cells.</li>
</ul>
</div>
<p><br/></p>
<ul>
<li><strong>Create histograms</strong></li>
</ul>
<pre class="r"><code>hist(x, col = "steelblue", frame = FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/histogram-density-plots-histogram-1.png" title="" alt="" width="432" /></p>
<pre class="r"><code># Change the number of breaks
hist(x, col = "steelblue", frame = FALSE,
     breaks = 30)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/histogram-density-plots-histogram-2.png" title="" alt="" width="432" /></p>
</div>
<div id="create-density-plots-density" class="section level1">
<h1>Create density plots: density()</h1>
<p>The function <strong>density</strong>() is used to estimate kernel density.</p>
<pre class="r"><code># Compute the density data
dens <- density(mtcars$mpg)
# plot density
plot(dens, frame = FALSE, col = "steelblue", 
     main = "Density plot of mpg") </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/histogram-density-plots-density-plot-1.png" title="" alt="" width="384" /></p>
<pre class="r"><code># Fill the density plot using polygon()
plot(dens, frame = FALSE, col = "steelblue", 
     main = "Density plot of mpg") 
polygon(dens, col = "steelblue")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/histogram-density-plots-fill-density-plot-1.png" title="" alt="" width="384" /></p>
</div>
<div id="related-articles" class="section level1">
<h1>Related articles</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/creating-and-saving-graphs-r-base-graphs">Creating and Saving Graphs in R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plots-r-base-graphs">Scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plot-matrices-r-base-graphs">Scatter Plot Matrices</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/box-plots-r-base-graphs">Box Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/strip-charts-1-d-scatter-plots-r-base-graphs">Strip Charts: 1-D scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/bar-plots-r-base-graphs">Bar Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/line-plots-r-base-graphs">Line Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/pie-charts-r-base-graphs">Pie Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/dot-charts-r-base-graphs">Dot Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/plot-group-means-and-confidence-intervals-r-base-graphs">Plot Group Means and Confidence Intervals</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/graphical-parameters">Graphical Parameters</a></li>
</ul>
</div>
<div id="see-also" class="section level1">
<h1>See also</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/lattice-graphs">Lattice Graphs</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/ggplot2-essentials">ggplot2 Graphs</a></li>
</ul>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.2.4). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->


<!-- END HTML -->]]></description>
			<pubDate>Fri, 06 May 2016 07:05:12 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Pie Charts - R Base Graphs]]></title>
			<link>https://www.sthda.com/english/wiki/pie-charts-r-base-graphs</link>
			<guid>https://www.sthda.com/english/wiki/pie-charts-r-base-graphs</guid>
			<description><![CDATA[<!-- START HTML -->

            
  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">


<div id="TOC">
<ul>
<li><a href="#pleleminary-tasks">Pleleminary tasks</a></li>
<li><a href="#create-some-data">Create some data</a></li>
<li><a href="#create-basic-pie-charts-pie">Create basic pie charts: pie()</a></li>
<li><a href="#create-3d-pie-charts-plotixpie3d">Create 3D pie charts: plotix::pie3D()</a></li>
<li><a href="#related-articles">Related articles</a></li>
<li><a href="#see-also">See also</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>Previously, we described the <a href="https://www.sthda.com/english/english/wiki/r-basics-quick-and-easy">essentials of R programming</a> and provided quick start guides for <a href="https://www.sthda.com/english/english/wiki/importing-data-into-r">importing data</a> into <strong>R</strong>.</p>
<br/>
<div class="block">
Here, we’ll describe how to create <strong>pie charts</strong> in R. The R base function <strong>pie</strong>() can be used for this.
</div>
<p><br/></p>
<div id="pleleminary-tasks" class="section level1">
<h1>Pleleminary tasks</h1>
<ol style="list-style-type: decimal">
<li><p><strong>Launch RStudio</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/running-rstudio-and-setting-up-your-working-directory-easy-r-programming">Running RStudio and setting up your working directory</a></p></li>
<li><p><strong>Prepare your data</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/best-practices-in-preparing-data-files-for-importing-into-r">Best practices for preparing your data</a> and save it in an external .txt tab or .csv files</p></li>
<li><p><strong>Import your data</strong> into <strong>R</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/fast-reading-of-data-from-txt-csv-files-into-r-readr-package">Fast reading of data from txt|csv files into R: readr package</a>.</p></li>
</ol>
</div>
<div id="create-some-data" class="section level1">
<h1>Create some data</h1>
<pre class="r"><code>df <- data.frame(
  group = c("Male", "Female", "Child"),
  value = c(25, 25, 50)
  )

df</code></pre>
<pre><code>##    group value
## 1   Male    25
## 2 Female    25
## 3  Child    50</code></pre>
</div>
<div id="create-basic-pie-charts-pie" class="section level1">
<h1>Create basic pie charts: pie()</h1>
<p>The function <strong>pie</strong>() can be used to draw a <strong>pie chart</strong>.</p>
<pre class="r"><code>pie(x, labels = names(x), radius = 0.8)</code></pre>
<br/>
<div class="block">
<ul>
<li><strong>x</strong>: a vector of non-negative numerical quantities. The values in x are displayed as the areas of pie slices.</li>
<li><strong>labels</strong>: character strings giving names for the slices.</li>
<li><strong>radius</strong>: radius of the pie circle. If the character strings labeling the slices are long it may be necessary to use a smaller radius.</li>
</ul>
</div>
<p><br/></p>
<pre class="r"><code>pie(df$value, labels = df$group, radius = 1)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/pie-charts-pie-1.png" title="" alt="" width="384" /></p>
<pre class="r"><code># Change colors
pie(df$value, labels = df$group, radius = 1,
    col = c("#999999", "#E69F00", "#56B4E9"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/pie-charts-pie-2.png" title="" alt="" width="384" /></p>
</div>
<div id="create-3d-pie-charts-plotixpie3d" class="section level1">
<h1>Create 3D pie charts: plotix::pie3D()</h1>
<p>Te function <strong>pie3D</strong>()[in <strong>plotrix</strong> package] can be used to draw a 3D pie chart.</p>
<p><strong>Install</strong> plotrix package:</p>
<pre class="r"><code>install.packages("plotrix")</code></pre>
<p>Use <strong>pie3D</strong>():</p>
<pre class="r"><code># 3D pie chart
library("plotrix")
pie3D(df$value, labels = df$group, radius = 1.5, 
      col = c("#999999", "#E69F00", "#56B4E9"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/pie-charts-pie3D-1.png" title="" alt="" width="384" /></p>
<pre class="r"><code># Explode the pie chart
pie3D(df$value, labels = df$group, radius = 1.5,
      col = c("#999999", "#E69F00", "#56B4E9"),
      explode = 0.1)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/pie-charts-pie3D-2.png" title="" alt="" width="384" /></p>
</div>
<div id="related-articles" class="section level1">
<h1>Related articles</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/creating-and-saving-graphs-r-base-graphs">Creating and Saving Graphs in R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plots-r-base-graphs">Scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plot-matrices-r-base-graphs">Scatter Plot Matrices</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/box-plots-r-base-graphs">Box Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/strip-charts-1-d-scatter-plots-r-base-graphs">Strip Charts: 1-D scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/bar-plots-r-base-graphs">Bar Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/line-plots-r-base-graphs">Line Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/histogram-and-density-plots-r-base-graphs">Histogram and Density Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/dot-charts-r-base-graphs">Dot Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/plot-group-means-and-confidence-intervals-r-base-graphs">Plot Group Means and Confidence Intervals</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/graphical-parameters">Graphical Parameters</a></li>
</ul>
</div>
<div id="see-also" class="section level1">
<h1>See also</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/lattice-graphs">Lattice Graphs</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/ggplot2-essentials">ggplot2 Graphs</a></li>
</ul>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.2.4). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->

<!-- END HTML -->]]></description>
			<pubDate>Fri, 06 May 2016 06:57:51 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Line Plots - R Base Graphs]]></title>
			<link>https://www.sthda.com/english/wiki/line-plots-r-base-graphs</link>
			<guid>https://www.sthda.com/english/wiki/line-plots-r-base-graphs</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#pleleminary-tasks">Pleleminary tasks</a></li>
<li><a href="#r-base-functions-plot-and-lines">R base functions: plot() and lines()</a></li>
<li><a href="#create-some-data">Create some data</a></li>
<li><a href="#basic-line-plots">Basic line plots</a></li>
<li><a href="#plots-with-multiple-lines">Plots with multiple lines</a></li>
<li><a href="#related-articles">Related articles</a></li>
<li><a href="#see-also">See also</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>Previously, we described the <a href="https://www.sthda.com/english/english/wiki/r-basics-quick-and-easy">essentials of R programming</a> and provided quick start guides for <a href="https://www.sthda.com/english/english/wiki/importing-data-into-r">importing data</a> into <strong>R</strong>.</p>
<br/>
<div class="block">
Here, we’ll describe how to create <strong>line plots</strong> in R. The function <strong>plot</strong>() or <strong>lines</strong>() can be used to create a line plot.
</div>
<p><br/></p>
<div id="pleleminary-tasks" class="section level1">
<h1>Pleleminary tasks</h1>
<ol style="list-style-type: decimal">
<li><p><strong>Launch RStudio</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/running-rstudio-and-setting-up-your-working-directory-easy-r-programming">Running RStudio and setting up your working directory</a></p></li>
<li><p><strong>Prepare your data</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/best-practices-in-preparing-data-files-for-importing-into-r">Best practices for preparing your data</a> and save it in an external .txt tab or .csv files</p></li>
<li><p><strong>Import your data</strong> into <strong>R</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/fast-reading-of-data-from-txt-csv-files-into-r-readr-package">Fast reading of data from txt|csv files into R: readr package</a>.</p></li>
</ol>
</div>
<div id="r-base-functions-plot-and-lines" class="section level1">
<h1>R base functions: plot() and lines()</h1>
<p>The simplified format of <strong>plot</strong>() and <strong>lines</strong>() is as follow.</p>
<pre class="r"><code>plot(x, y, type = "l", lty = 1)

lines(x, y, type = "l", lty = 1)</code></pre>
<br/>
<div class="block">
<ul>
<li><strong>x, y</strong>: coordinate vectors of points to join</li>
<li><strong>type</strong>: character indicating the type of plotting. Allowed values are:
<ul>
<li>“p” for points</li>
<li>“l” for lines</li>
<li>“b” for both points and lines</li>
<li>“c” for empty points joined by lines</li>
<li>“o” for overplotted points and lines</li>
<li>“s” and “S” for stair steps</li>
<li>“n” does not produce any points or lines</li>
</ul></li>
<li><strong>lty</strong>: line types. Line types can either be specified as an integer (0=blank, 1=solid (default), 2=dashed, 3=dotted, 4=dotdash, 5=longdash, 6=twodash) or as one of the character strings “blank”, “solid”, “dashed”, “dotted”, “dotdash”, “longdash”, or “twodash”, where “blank” uses ‘invisible lines’ (i.e., does not draw them).</li>
</ul>
</div>
<p><br/></p>
</div>
<div id="create-some-data" class="section level1">
<h1>Create some data</h1>
<pre class="r"><code># Create some variables
x <- 1:10
y1 <- x*x
y2  <- 2*y1</code></pre>
<p>We’ll plot a plot with two lines: <strong>lines</strong>(x, y1) and <strong>lines</strong>(x, y2).</p>
<p><span class="warning">Note that the function <strong>lines</strong>() can not produce a plot on its own. However, it can be used to add <strong>lines</strong>() on an existing graph. This means that, first you have to use the function <strong>plot</strong>() to create an empty graph and then use the function <strong>lines</strong>() to add lines.</span></p>
</div>
<div id="basic-line-plots" class="section level1">
<h1>Basic line plots</h1>
<pre class="r"><code># Create a basic stair steps plot 
plot(x, y1, type = "S")

# Show both points and line
plot(x, y1, type = "b", pch = 19, 
     col = "red", xlab = "x", ylab = "y")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/line-plots-line-plot-1.png" title="" alt="" width="259.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/line-plots-line-plot-2.png" title="" alt="" width="259.2" /></p>
</div>
<div id="plots-with-multiple-lines" class="section level1">
<h1>Plots with multiple lines</h1>
<pre class="r"><code># Create a first line
plot(x, y1, type = "b", frame = FALSE, pch = 19, 
     col = "red", xlab = "x", ylab = "y")

# Add a second line
lines(x, y2, pch = 18, col = "blue", type = "b", lty = 2)

# Add a legend to the plot
legend("topleft", legend=c("Line 1", "Line 2"),
       col=c("red", "blue"), lty = 1:2, cex=0.8)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/line-plots-line-plot-multiple-1.png" title="" alt="" width="288" /></p>
</div>
<div id="related-articles" class="section level1">
<h1>Related articles</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/creating-and-saving-graphs-r-base-graphs">Creating and Saving Graphs in R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plots-r-base-graphs">Scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plot-matrices-r-base-graphs">Scatter Plot Matrices</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/box-plots-r-base-graphs">Box Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/strip-charts-1-d-scatter-plots-r-base-graphs">Strip Charts: 1-D scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/bar-plots-r-base-graphs">Bar Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/pie-charts-r-base-graphs">Pie Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/histogram-and-density-plots-r-base-graphs">Histogram and Density Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/dot-charts-r-base-graphs">Dot Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/plot-group-means-and-confidence-intervals-r-base-graphs">Plot Group Means and Confidence Intervals</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/graphical-parameters">Graphical Parameters</a></li>
</ul>
</div>
<div id="see-also" class="section level1">
<h1>See also</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/lattice-graphs">Lattice Graphs</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/ggplot2-essentials">ggplot2 Graphs</a></li>
</ul>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.2.4). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->


<!-- END HTML -->]]></description>
			<pubDate>Fri, 06 May 2016 06:51:08 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Bar Plots - R Base Graphs]]></title>
			<link>https://www.sthda.com/english/wiki/bar-plots-r-base-graphs</link>
			<guid>https://www.sthda.com/english/wiki/bar-plots-r-base-graphs</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#pleleminary-tasks">Pleleminary tasks</a></li>
<li><a href="#basic-bar-plots">Basic bar plots</a><ul>
<li><a href="#change-group-names">Change group names</a></li>
<li><a href="#change-color">Change color</a></li>
<li><a href="#change-main-title-and-axis-labels">Change main title and axis labels</a></li>
</ul></li>
<li><a href="#stacked-bar-plots">Stacked bar plots</a></li>
<li><a href="#grouped-bar-plots">Grouped bar plots</a></li>
<li><a href="#related-articles">Related articles</a></li>
<li><a href="#see-also">See also</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>Previously, we described the <a href="https://www.sthda.com/english/english/wiki/r-basics-quick-and-easy">essentials of R programming</a> and provided quick start guides for <a href="https://www.sthda.com/english/english/wiki/importing-data-into-r">importing data</a> into <strong>R</strong>.</p>
<br/>
<div class="block">
Here, we’ll describe how to create <strong>bar plots</strong> in R. The function <strong>barplot</strong>() can be used to create a <strong>bar plot</strong> with vertical or horizontal bars.
</div>
<p><br/></p>
<div id="pleleminary-tasks" class="section level1">
<h1>Pleleminary tasks</h1>
<ol style="list-style-type: decimal">
<li><p><strong>Launch RStudio</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/running-rstudio-and-setting-up-your-working-directory-easy-r-programming">Running RStudio and setting up your working directory</a></p></li>
<li><p><strong>Prepare your data</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/best-practices-in-preparing-data-files-for-importing-into-r">Best practices for preparing your data</a> and save it in an external .txt tab or .csv files</p></li>
<li><p><strong>Import your data</strong> into <strong>R</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/fast-reading-of-data-from-txt-csv-files-into-r-readr-package">Fast reading of data from txt|csv files into R: readr package</a>.</p></li>
</ol>
<p><span class="success">Here, we’ll use the R built-in VADeaths data set.</span></p>
<p>Data set: <em>VADeaths</em></p>
<pre class="r"><code># Data set
VADeaths</code></pre>
<pre><code>##       Rural Male Rural Female Urban Male Urban Female
## 50-54       11.7          8.7       15.4          8.4
## 55-59       18.1         11.7       24.3         13.6
## 60-64       26.9         20.3       37.0         19.3
## 65-69       41.0         30.9       54.6         35.1
## 70-74       66.0         54.3       71.1         50.0</code></pre>
<pre class="r"><code># Subset
x <- VADeaths[1:3, "Rural Male"]
x</code></pre>
<pre><code>## 50-54 55-59 60-64 
##  11.7  18.1  26.9</code></pre>
</div>
<div id="basic-bar-plots" class="section level1">
<h1>Basic bar plots</h1>
<pre class="r"><code># Bar plot of one variable
barplot(x)

# Horizontal bar plot
barplot(x, horiz = TRUE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/bar-plots-basic-bar-plot-1.png" title="" alt="" width="259.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/bar-plots-basic-bar-plot-2.png" title="" alt="" width="259.2" /></p>
<div id="change-group-names" class="section level2">
<h2>Change group names</h2>
<pre class="r"><code>barplot(x, names.arg = c("A", "B", "C"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/bar-plots-bar-plot-group-labels-1.png" title="" alt="" width="259.2" /></p>
</div>
<div id="change-color" class="section level2">
<h2>Change color</h2>
<pre class="r"><code># Change border and fill color using one single color
barplot(x, col = "white", border = "steelblue")

# Change the color of border.
#  Use different colors for each group
barplot(x, col = "white",
        border = c("#999999", "#E69F00", "#56B4E9"))

# Change fill color : single color
barplot(x, col = "steelblue")

# Change fill color: multiple colors
barplot(x, col = c("#999999", "#E69F00", "#56B4E9"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/bar-plots-bar-plot-change-color-1.png" title="" alt="" width="259.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/bar-plots-bar-plot-change-color-2.png" title="" alt="" width="259.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/bar-plots-bar-plot-change-color-3.png" title="" alt="" width="259.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/bar-plots-bar-plot-change-color-4.png" title="" alt="" width="259.2" /></p>
</div>
<div id="change-main-title-and-axis-labels" class="section level2">
<h2>Change main title and axis labels</h2>
<pre class="r"><code># Change axis titles
# Change color (col = "gray") and remove frame
barplot(x, main = "Death Rates in Virginia",
        xlab = "Age", ylab = "Rate")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/bar-plots-bar-plots-titles-1.png" title="" alt="" width="288" /></p>
</div>
</div>
<div id="stacked-bar-plots" class="section level1">
<h1>Stacked bar plots</h1>
<pre class="r"><code>barplot(VADeaths,
         col = c("lightblue", "mistyrose", "lightcyan", 
                 "lavender", "cornsilk"),
        legend = rownames(VADeaths))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/bar-plots-stacked-bar-plots-1.png" title="" alt="" width="336" /></p>
</div>
<div id="grouped-bar-plots" class="section level1">
<h1>Grouped bar plots</h1>
<pre class="r"><code>barplot(VADeaths,
         col = c("lightblue", "mistyrose", "lightcyan", 
                 "lavender", "cornsilk"),
        legend = rownames(VADeaths), beside = TRUE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/bar-plots-grouped-bar-plots-1.png" title="" alt="" width="528" /></p>
<p><span class="success">It’s also possible to add legends to a plot using the function <strong>legend</strong>() as follow.</span></p>
<pre class="r"><code># Define a set of colors
my_colors <- c("lightblue", "mistyrose", "lightcyan", 
                 "lavender", "cornsilk")
# Bar plot
barplot(VADeaths, col = my_colors, beside = TRUE)
# Add legend
legend("topleft", legend = rownames(VADeaths), 
       fill = my_colors, box.lty = 0, cex = 0.8)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/bar-plots-grouped-bar-plots-legend-1.png" title="" alt="" width="528" /></p>
<ul>
<li><strong>box.lty = 0</strong>: Remove the box around the legend</li>
<li><strong>cex = 0.8</strong>: legend text size</li>
</ul>
</div>
<div id="related-articles" class="section level1">
<h1>Related articles</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/creating-and-saving-graphs-r-base-graphs">Creating and Saving Graphs in R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plots-r-base-graphs">Scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plot-matrices-r-base-graphs">Scatter Plot Matrices</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/box-plots-r-base-graphs">Box Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/strip-charts-1-d-scatter-plots-r-base-graphs">Strip Charts: 1-D scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/line-plots-r-base-graphs">Line Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/pie-charts-r-base-graphs">Pie Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/histogram-and-density-plots-r-base-graphs">Histogram and Density Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/dot-charts-r-base-graphs">Dot Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/plot-group-means-and-confidence-intervals-r-base-graphs">Plot Group Means and Confidence Intervals</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/graphical-parameters">Graphical Parameters</a></li>
</ul>
</div>
<div id="see-also" class="section level1">
<h1>See also</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/lattice-graphs">Lattice Graphs</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/ggplot2-essentials">ggplot2 Graphs</a></li>
</ul>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.2.4). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->

<!-- END HTML -->]]></description>
			<pubDate>Fri, 06 May 2016 06:43:10 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Strip charts: 1-D scatter plots - R Base Graphs]]></title>
			<link>https://www.sthda.com/english/wiki/strip-charts-1-d-scatter-plots-r-base-graphs</link>
			<guid>https://www.sthda.com/english/wiki/strip-charts-1-d-scatter-plots-r-base-graphs</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">


<div id="TOC">
<ul>
<li><a href="#pleleminary-tasks">Pleleminary tasks</a></li>
<li><a href="#r-base-function-stripchart">R base function: stripchart()</a></li>
<li><a href="#create-strip-charts">Create strip charts</a></li>
<li><a href="#related-articles">Related articles</a></li>
<li><a href="#see-also">See also</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>Previously, we described the <a href="https://www.sthda.com/english/english/wiki/r-basics-quick-and-easy">essentials of R programming</a> and provided quick start guides for <a href="https://www.sthda.com/english/english/wiki/importing-data-into-r">importing data</a> into <strong>R</strong>.</p>
<br/>
<div class="block">
Here, we’ll describe how to create <strong>strip charts</strong> (i.e., one dimensional scatter plots or dot plots) in R. These plots are a good alternative to box plots when sample sizes are small.
</div>
<p><br/></p>
<div id="pleleminary-tasks" class="section level1">
<h1>Pleleminary tasks</h1>
<ol style="list-style-type: decimal">
<li><p><strong>Launch RStudio</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/running-rstudio-and-setting-up-your-working-directory-easy-r-programming">Running RStudio and setting up your working directory</a></p></li>
<li><p><strong>Prepare your data</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/best-practices-in-preparing-data-files-for-importing-into-r">Best practices for preparing your data</a> and save it in an external .txt tab or .csv files</p></li>
<li><p><strong>Import your data</strong> into <strong>R</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/fast-reading-of-data-from-txt-csv-files-into-r-readr-package">Fast reading of data from txt|csv files into R: readr package</a>.</p></li>
</ol>
<p><span class="success">Here, we’ll use the <a href="https://www.sthda.com/english/english/wiki/r-built-in-data-sets">R built-in ToothGrowth data set</a>.</span></p>
<pre class="r"><code>ToothGrowth$dose <- as.factor(ToothGrowth$dose)

# Print the first 6 rows
head(ToothGrowth, 6)</code></pre>
<pre><code>##    len supp dose
## 1  4.2   VC  0.5
## 2 11.5   VC  0.5
## 3  7.3   VC  0.5
## 4  5.8   VC  0.5
## 5  6.4   VC  0.5
## 6 10.0   VC  0.5</code></pre>
</div>
<div id="r-base-function-stripchart" class="section level1">
<h1>R base function: stripchart()</h1>
<pre class="r"><code>stripchart(x, data = NULL method = "overplot", jitter = 0.1)</code></pre>
<br/>
<div class="block">
<ul>
<li><strong>x</strong>: the data from which the plots are to be produced. Allowed values are one or a list of numeric vector, each corresponding to a component plot.</li>
<li><strong>data</strong>: a data.frame (or list) from which the variables in x should be taken.</li>
<li><strong>Method</strong>: the method to be used to separate coincident points. Allowed values are one of “overplot”, “jitter” or “stack”.</li>
<li><strong>jitter</strong>: when method = “jitter” is used, jitter gives the amount of jittering applied.</li>
</ul>
</div>
<p><br/></p>
</div>
<div id="create-strip-charts" class="section level1">
<h1>Create strip charts</h1>
<pre class="r"><code># Plot len by dose
stripchart(len ~ dose, data = ToothGrowth,
         pch = 19, frame = FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/strip-charts-stripchart-1.png" title="" alt="" width="288" /></p>
<pre class="r"><code># Vertical plot using method = "jitter"
stripchart(len ~ dose, data = ToothGrowth,
         pch = 19, frame = FALSE, vertical = TRUE,
         method = "jitter")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/strip-charts-stripchart-2.png" title="" alt="" width="288" /></p>
<pre class="r"><code># Change point shapes (pch) and colors by groups
# add main title and axis labels
stripchart(len ~ dose, data = ToothGrowth,
         frame = FALSE, vertical = TRUE,
         method = "jitter", pch = c(21, 18, 16),
         col = c("#999999", "#E69F00", "#56B4E9"),
         main = "Length by dose", xlab = "Dose", ylab = "Length")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/strip-charts-stripchart-customized-1.png" title="" alt="" width="384" /></p>
</div>
<div id="related-articles" class="section level1">
<h1>Related articles</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/creating-and-saving-graphs-r-base-graphs">Creating and Saving Graphs in R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plots-r-base-graphs">Scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plot-matrices-r-base-graphs">Scatter Plot Matrices</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/box-plots-r-base-graphs">Box Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/bar-plots-r-base-graphs">Bar Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/line-plots-r-base-graphs">Line Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/pie-charts-r-base-graphs">Pie Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/histogram-and-density-plots-r-base-graphs">Histogram and Density Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/dot-charts-r-base-graphs">Dot Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/plot-group-means-and-confidence-intervals-r-base-graphs">Plot Group Means and Confidence Intervals</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/graphical-parameters">Graphical Parameters</a></li>
</ul>
</div>
<div id="see-also" class="section level1">
<h1>See also</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/lattice-graphs">Lattice Graphs</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/ggplot2-essentials">ggplot2 Graphs</a></li>
</ul>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.2.4). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->


<!-- END HTML -->]]></description>
			<pubDate>Thu, 05 May 2016 23:24:23 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Box Plots - R Base Graphs]]></title>
			<link>https://www.sthda.com/english/wiki/box-plots-r-base-graphs</link>
			<guid>https://www.sthda.com/english/wiki/box-plots-r-base-graphs</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">



<div id="TOC">
<ul>
<li><a href="#pleleminary-tasks">Pleleminary tasks</a></li>
<li><a href="#r-base-box-plots-boxplot">R base box plots: boxplot()</a></li>
<li><a href="#box-plot-with-the-number-of-observations-gplotsboxplot2">Box plot with the number of observations: gplots::boxplot2()</a></li>
<li><a href="#summary">Summary</a></li>
<li><a href="#related-articles">Related articles</a></li>
<li><a href="#see-also">See also</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>Previously, we described the <a href="https://www.sthda.com/english/english/wiki/r-basics-quick-and-easy">essentials of R programming</a> and provided quick start guides for <a href="https://www.sthda.com/english/english/wiki/importing-data-into-r">importing data</a> into <strong>R</strong>.</p>
<br/>
<div class="block">
Here, we’ll describe how to create <strong>box plots</strong> in R.
</div>
<p><br/></p>
<div id="pleleminary-tasks" class="section level1">
<h1>Pleleminary tasks</h1>
<ol style="list-style-type: decimal">
<li><p><strong>Launch RStudio</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/running-rstudio-and-setting-up-your-working-directory-easy-r-programming">Running RStudio and setting up your working directory</a></p></li>
<li><p><strong>Prepare your data</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/best-practices-in-preparing-data-files-for-importing-into-r">Best practices for preparing your data</a> and save it in an external .txt tab or .csv files</p></li>
<li><p><strong>Import your data</strong> into <strong>R</strong> as described here: <a href="https://www.sthda.com/english/english/wiki/fast-reading-of-data-from-txt-csv-files-into-r-readr-package">Fast reading of data from txt|csv files into R: readr package</a>.</p></li>
</ol>
<p><span class="success">Here, we’ll use the <a href="https://www.sthda.com/english/english/wiki/r-built-in-data-sets">R built-in ToothGrowth data set</a>.</span></p>
<pre class="r"><code># Print the first 6 rows
head(ToothGrowth, 6)</code></pre>
<pre><code>##    len supp dose
## 1  4.2   VC  0.5
## 2 11.5   VC  0.5
## 3  7.3   VC  0.5
## 4  5.8   VC  0.5
## 5  6.4   VC  0.5
## 6 10.0   VC  0.5</code></pre>
</div>
<div id="r-base-box-plots-boxplot" class="section level1">
<h1>R base box plots: boxplot()</h1>
<p>Draw a box plot of teeth length (<em>len</em>):</p>
<ul>
<li><strong>Basic box plots</strong></li>
</ul>
<pre class="r"><code># Box plot of one variable
boxplot(ToothGrowth$len)

# Box plots by groups (dose)
# remove frame
boxplot(len ~ dose, data = ToothGrowth, frame = FALSE)

# Horizontal box plots
boxplot(len ~ dose, data = ToothGrowth, frame = FALSE,
        horizontal = TRUE)

# Notched box plots
boxplot(len ~ dose, data = ToothGrowth, frame = FALSE,
        notch = TRUE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/box-plots-basic-boxplot-1.png" title="" alt="" width="259.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/box-plots-basic-boxplot-2.png" title="" alt="" width="259.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/box-plots-basic-boxplot-3.png" title="" alt="" width="259.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/box-plots-basic-boxplot-4.png" title="" alt="" width="259.2" /></p>
<p><span class="success">Notch is used to compare groups. In the notched boxplot, if two boxes’ notches do not overlap this is “strong evidence” their medians differ (Chambers et al., 1983, p. 62).</span></p>
<ul>
<li><strong>Change group names</strong></li>
</ul>
<pre class="r"><code>boxplot(len ~ dose, data = ToothGrowth, frame = FALSE,
        names = c("D0.5", "D1", "D2"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/box-plots-box-plot-group-labels-1.png" title="" alt="" width="259.2" /></p>
<ul>
<li><strong>Change color</strong></li>
</ul>
<pre class="r"><code># Change the color of border using one single color
boxplot(len ~ dose, data = ToothGrowth, frame = FALSE,
        border = "steelblue")

# Change the color of border.
#  Use different colors for each group
boxplot(len ~ dose, data = ToothGrowth, frame = FALSE,
        border = c("#999999", "#E69F00", "#56B4E9"))

# Change fill color : single color
boxplot(len ~ dose, data = ToothGrowth, frame = FALSE,
        col = "steelblue")

# Change fill color: multiple colors
boxplot(len ~ dose, data = ToothGrowth, frame = FALSE,
        col = c("#999999", "#E69F00", "#56B4E9"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/box-plots-box-plot-change-color-1.png" title="" alt="" width="259.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/box-plots-box-plot-change-color-2.png" title="" alt="" width="259.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/box-plots-box-plot-change-color-3.png" title="" alt="" width="259.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/box-plots-box-plot-change-color-4.png" title="" alt="" width="259.2" /></p>
<ul>
<li><strong>Box plot with multiple groups</strong></li>
</ul>
<pre class="r"><code>boxplot(len ~ supp*dose, data = ToothGrowth,
        col = c("white", "steelblue"), frame = FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/box-plots-box-plot-multiple-groups-1.png" title="" alt="" width="384" /></p>
<ul>
<li><strong>Change main title and axis labels</strong></li>
</ul>
<pre class="r"><code># Change axis titles
# Change color (col = "gray") and remove frame
# Create notched box plot
boxplot(len ~ dose, data = ToothGrowth,
        main = "Plot of length by dose",
        xlab = "Dose (mg)", ylab = "Length",
        col = "lightgray", frame = FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/box-plots-box-plot-titles-1.png" title="" alt="" width="288" /></p>
</div>
<div id="box-plot-with-the-number-of-observations-gplotsboxplot2" class="section level1">
<h1>Box plot with the number of observations: gplots::boxplot2()</h1>
<p><span class="success">The function <strong>boxplot2</strong>()[in <strong>gplots</strong> package] can be used to create a box plot annotated with the number of observations.</span></p>
<p>Install <strong>gplots</strong>:</p>
<pre class="r"><code>install.packages("gplots")</code></pre>
<p>Use <strong>boxplot2</strong>() [in gplots]:</p>
<pre class="r"><code>library("gplots")
# Box plot with annotation
boxplot2(len ~ dose, data = ToothGrowth,
         frame = FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/box-plots-box-plot2-1.png" title="" alt="" width="259.2" /></p>
<pre class="r"><code># Put the annotation at the top
boxplot2(len ~ dose, data = ToothGrowth,
         frame = FALSE, top = TRUE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/box-plots-box-plot2-2.png" title="" alt="" width="259.2" /></p>
</div>
<div id="summary" class="section level1">
<h1>Summary</h1>
<ul>
<li>Create basic box plots:</li>
</ul>
<pre class="r"><code>boxplot(len ~ dose, data = ToothGrowth, frame = FALSE)</code></pre>
<ul>
<li>Box plots with number of observations:</li>
</ul>
<pre class="r"><code>gplots::boxplot2(len ~ dose, data = ToothGrowth,
                 frame = FALSE, top = TRUE)</code></pre>
</div>
<div id="related-articles" class="section level1">
<h1>Related articles</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/creating-and-saving-graphs-r-base-graphs">Creating and Saving Graphs in R</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plots-r-base-graphs">Scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/scatter-plot-matrices-r-base-graphs">Scatter Plot Matrices</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/strip-charts-1-d-scatter-plots-r-base-graphs">Strip Charts: 1-D scatter Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/bar-plots-r-base-graphs">Bar Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/line-plots-r-base-graphs">Line Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/pie-charts-r-base-graphs">Pie Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/histogram-and-density-plots-r-base-graphs">Histogram and Density Plots</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/dot-charts-r-base-graphs">Dot Charts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/plot-group-means-and-confidence-intervals-r-base-graphs">Plot Group Means and Confidence Intervals</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/graphical-parameters">Graphical Parameters</a></li>
</ul>
</div>
<div id="see-also" class="section level1">
<h1>See also</h1>
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/lattice-graphs">Lattice Graphs</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/ggplot2-essentials">ggplot2 Graphs</a></li>
</ul>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.2.4). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->



<!-- END HTML -->]]></description>
			<pubDate>Thu, 05 May 2016 23:19:03 +0200</pubDate>
			
		</item>
		
	</channel>
</rss>
