<?xml version="1.0" encoding="UTF-8" ?>
<!-- RSS generated by PHPBoost on Sat, 09 May 2026 10:12:38 +0200 -->

<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/28" rel="self" type="application/rss+xml"/>
		<link>https://www.sthda.com</link>
		<description><![CDATA[Last articles of the category: easyGgplot2]]></description>
		<copyright>(C) 2005-2026 PHPBoost</copyright>
		<language>en</language>
		<generator>PHPBoost</generator>
		
		
		<item>
			<title><![CDATA[ggplot2 violin plot : Easy function for data visualization using ggplot2 and R software]]></title>
			<link>https://www.sthda.com/english/wiki/ggplot2-violin-plot-easy-function-for-data-visualization-using-ggplot2-and-r-software</link>
			<guid>https://www.sthda.com/english/wiki/ggplot2-violin-plot-easy-function-for-data-visualization-using-ggplot2-and-r-software</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">
>

<div id="TOC">
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#install-and-load-easyggplot2-package">Install and load easyGgplot2 package</a></li>
<li><a href="#data-format">Data format</a></li>
<li><a href="#basic-violin-plot">Basic violin plot</a></li>
<li><a href="#violin-plot-with-mean-point-and-dots">Violin plot with mean point and dots</a></li>
<li><a href="#change-the-violin-plot-line-type-and-point-shape">Change the violin plot line type and point shape</a></li>
<li><a href="#customize-your-violin-plot">Customize your violin plot</a><ul>
<li><a href="#parameters">Parameters</a></li>
<li><a href="#main-title-and-axis-labels">Main title and axis labels</a></li>
<li><a href="#axis-ticks">Axis ticks</a></li>
<li><a href="#background-and-colors">Background and colors</a><ul>
<li><a href="#change-violin-plot-background-and-fill-colors">Change violin plot background and fill colors</a></li>
<li><a href="#change-violin-plot-color-according-to-the-group">Change violin plot color according to the group</a></li>
</ul></li>
<li><a href="#legend">Legend</a><ul>
<li><a href="#legend-position">Legend position</a></li>
<li><a href="#legend-background-color-title-and-text-font-styles">Legend background color, title and text font styles</a></li>
<li><a href="#change-the-order-of-items-in-the-legend-remove-plot-legend">Change the order of items in the legend, remove plot legend</a></li>
<li><a href="#axis-scales">Axis scales</a></li>
</ul></li>
<li><a href="#create-a-customized-plots-with-few-r-code">Create a customized plots with few R code</a></li>
</ul></li>
<li><a href="#violin-plot-with-multiple-groups">Violin plot with multiple groups</a></li>
<li><a href="#facet-split-a-plot-into-a-matrix-of-panels">Facet : split a plot into a matrix of panels</a><ul>
<li><a href="#faceting-with-one-variable">Faceting with one variable</a></li>
<li><a href="#facet-with-two-variables">Facet with two variables</a></li>
<li><a href="#facet-scales">Facet scales</a></li>
<li><a href="#facet-label-apperance">Facet label apperance</a></li>
</ul></li>
<li><a href="#ggplot2.violinplot-function">ggplot2.violinplot function</a><ul>
<li><a href="#description">Description</a></li>
<li><a href="#usage">usage</a></li>
<li><a href="#arguments">Arguments</a></li>
<li><a href="#examples">Examples</a></li>
</ul></li>
<li><a href="#easy-ggplot2-ebook">Easy ggplot2 ebook</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<div id="introduction" class="section level1">
<h1>Introduction</h1>
<p><strong>ggplot2.violinplot</strong> is an easy to use function custom function to plot and customize easily a <strong>violin plot</strong> using <strong>ggplot2</strong> and <strong>R software</strong>. ggplot2.violinplot function is from <a href="https://www.sthda.com/english/english/wiki/easyggplot2"><strong>easyGgplot2</strong></a> R package. An R script is available in the next section to install the package.</p>
<p>The <strong>violin plot</strong> is similar to <a href="https://www.sthda.com/english/english/wiki/ggplot2-boxplot-easy-box-and-whisker-plots-maker-function"><strong>box plots</strong></a>, except that they also show the kernel probability density of the data at different value. Typically violin plots will include a marker for the median of the data and a box indicating the interquartile range, as in standard box plots (<a href="http://en.wikipedia.org/wiki/Violin_plot">wiki</a>).</p>
<p>The aim of this <strong>tutorial</strong> is to show you step by step, how to plot and customize a violin plot using ggplot2.violinplot function [easyGgplot2 package].</p>
<p>At the end of this <strong>tutorial</strong> you will be able to draw, with few R code, the following plots:</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-demo.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="336" /></p>

<p><span class="warning"><strong>ggplot2.violinplot</strong> function is described in detail at the end of this document.</span></p>
</div>
<div id="install-and-load-easyggplot2-package" class="section level1">
<h1>Install and load easyGgplot2 package</h1>
<p><strong>easyGgplot2</strong> R package can be installed as follow :</p>
<pre class="r"><code>install.packages("devtools")
library(devtools)
install_github("easyGgplot2", "kassambara")</code></pre>
<p>Load the package using this R code :</p>
<pre class="r"><code>library(easyGgplot2)</code></pre>
</div>
<div id="data-format" class="section level1">
<h1>Data format</h1>
<p><span class="success">The data must be a numeric vector or a data.frame (columns are variables and rows are observations).</span></p>
<p>ToothGrowth data is used in the following examples.</p>
<pre class="r"><code># create a numeric vector
numVector<-rnorm(100)
head(numVector)</code></pre>
<pre><code>## [1] -1.089173  0.004361  0.650597  0.423704  1.147449  0.837064</code></pre>
<pre class="r"><code># data.frame
df <- ToothGrowth
head(df)</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>
<br/>

<div class="block">
<p>ToothGrowth describes the effect of Vitamin C on Tooth growth in Guinea pigs. The response is the length (len) of teeth in each of 10 guinea pigs at each of three dose levels of Vitamin C (0.5, 1, and 2 mg) with each of two delivery methods (orange juice or ascorbic acid).</p>
The data is a data frame with 60 observations on 3 variables.
* [,1] len numeric Tooth length.
* [,2] supp factor Supplement type (VC or OJ).
* [,3] dose numeric Dose in milligrams.

</div>
<p><br/></p>
</div>
<div id="basic-violin-plot" class="section level1">
<h1>Basic violin plot</h1>
<pre class="r"><code># Violin plot from a single numeric vector 
ggplot2.violinplot(data=numVector)

# Basic violin plot from the vector "len"
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;)

# Change the orientation: Horizontal violin plot
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                orientation="horizontal")

# set trim to FALSE. If TRUE (default), trim the tails of 
  # the violins to the range of the data.
#If FALSE, don&amp;#39;t trim the tails
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;, yName=&amp;#39;len&amp;#39;,
                   trim=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-basic-violin-plot1.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-basic-violin-plot2.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-basic-violin-plot3.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-basic-violin-plot4.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /></p>
</div>
<div id="violin-plot-with-mean-point-and-dots" class="section level1">
<h1>Violin plot with mean point and dots</h1>
<p>Each dot represents one observation and the mean point corresponds to the mean value of the observations in a given group.</p>
<pre class="r"><code># Violin plot with mean point
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
      addMean=TRUE, meanPointShape=23, meanPointSize=3,
      meanPointColor="black", meanPointFill="blue")

#Violin plot with centered dots
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
      addDot=TRUE, dotSize=1, dotPosition="center")

# Violin plot with jittered dots. 
#jitter: degree of jitter in x direction
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
      addDot=TRUE, dotSize=1.7,
      dotPosition="jitter", jitter=0.2)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-violin-plot-with-dots1.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-violin-plot-with-dots2.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-violin-plot-with-dots3.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /></p>
</div>
<div id="change-the-violin-plot-line-type-and-point-shape" class="section level1">
<h1>Change the violin plot line type and point shape</h1>
<p><span class="warning">Different <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">point shapes</a> and <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">line types</a> can be used in the plot. By default, ggplot2 uses solid line type and circle shape.</span></p>
<ul>
<li>The different <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">point shapes</a> in R are described <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">here</a>.</li>
<li>The available <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">line types</a> are shown <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">here</a>.</li>
</ul>
<pre class="r"><code># Change the violin plot line color and line type
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                colour="red", linetype="dotted")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-line-type-and-point-shape.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="customize-your-violin-plot" class="section level1">
<h1>Customize your violin plot</h1>
<div id="parameters" class="section level2">
<h2>Parameters</h2>
<p>The arguments that can be used to customize x and y axis are listed below :</p>
<table>
<thead>
<tr class="header">
<th align="left">Parameters</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>mainTitle</strong></td>
<td align="left">the title of the plot</td>
</tr>
<tr class="even">
<td align="left"><strong>mainTitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style (“italic”, “bold”, “bold.italic”) and the color of x and y axis titles. Default value is: mainTitleFont=c(14, “bold”, “black”).</td>
</tr>
<tr class="odd">
<td align="left"><strong>xShowTitle, yShowTitle</strong></td>
<td align="left">if TRUE, x and y axis titles will be shown. Set the value to FALSE to hide axis labels. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtitle, ytitle</strong></td>
<td align="left">x and y axis labels. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xtitleFont, ytitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis titles. Possible values for the <strong>style</strong>:“plain”, “italic”, “bold”, “bold.italic”. Color can be specified as an hexadecimal code (e.g: “#FFCC00”) or by the name (e.g : “red”, “green”). Default values are <code>xtitleFont=c(14,"bold", "black"), ytitleFont=c(14,"bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xlim, ylim</strong></td>
<td align="left">limit for the x and y axis. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xScale, yScale</strong></td>
<td align="left">x and y axis scales. Possible values : c(“none”, “log2”, “log10”). e.g: yScale=“log2”. Default values are <code>NULL</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xShowTickLabel, yShowTickLabel</strong></td>
<td align="left">if TRUE, x and y axis tick mark labels will be shown. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xTickLabelFont, yTickLabelFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis tick label fonts. Default value are <code>xTickLabelFont=c(12, "bold", "black"), yTickLabelFont=c(12, "bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtickLabelRotation, ytickLabelRotation</strong></td>
<td align="left">Rotation angle of x and y axis tick labels. Default value are <code>0</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>hideAxisTicks</strong></td>
<td align="left">if TRUE, x and y axis ticks are hidden. Default value is <code>FALSE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>axisLine</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the line type and the color of axis lines. Default value is <code>c(0.5, "solid", "#E5E5E5")</code>.</td>
</tr>
</tbody>
</table>
<p>For more details follow this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2.customize</a>.</p>
</div>
<div id="main-title-and-axis-labels" class="section level2">
<h2>Main title and axis labels</h2>
<pre class="r"><code># Change main title and axis titles
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        mainTitle="Plot of length \n by dose",
        xtitle="Dose (mg)", ytitle="Length")

# Customize title styles. Possible values for the font style :
  # &amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
      xtitle="Dose (mg)", ytitle="Length",
      mainTitle="Plot of length \n by dose",
      mainTitleFont=c(14,"bold.italic", "red"),
      xtitleFont=c(14,"bold", "#993333"),
      ytitleFont=c(14,"bold", "#993333"))

# Hide x an y axis titles
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
     xShowTitle=FALSE, yShowTitle=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-title-and-axis-lables1.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-title-and-axis-lables2.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-title-and-axis-lables3.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /></p>
</div>
<div id="axis-ticks" class="section level2">
<h2>Axis ticks</h2>
<pre class="r"><code># Axis ticks labels and orientaion
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
      xShowTitle=FALSE, yShowTitle=FALSE,
      xTickLabelFont=c(14,"bold", "#993333"),
      yTickLabelFont=c(14,"bold", "#993333"),
      xtickLabelRotation=45, ytickLabelRotation=45)

# Hide axis tick labels
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        xShowTitle=FALSE, yShowTitle=FALSE,
        xShowTickLabel=FALSE, yShowTickLabel=FALSE)

# Hide axis ticks
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
      xShowTitle=FALSE, yShowTitle=FALSE,
      xShowTickLabel=FALSE, yShowTickLabel=FALSE,
      hideAxisTicks=TRUE)

# AxisLine : a vector of length 3 indicating the size,
  #the line type and the color of axis lines
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, 
      axisLine=c(1, "solid", "darkblue"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-axis-ticks1.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-axis-ticks2.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-axis-ticks3.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-axis-ticks4.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /></p>
</div>
<div id="background-and-colors" class="section level2">
<h2>Background and colors</h2>
<div id="change-violin-plot-background-and-fill-colors" class="section level3">
<h3>Change violin plot background and fill colors</h3>
<pre class="r"><code># change background color to "white". Default is "gray"
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;, yName=&amp;#39;len&amp;#39;,
                backgroundColor="white")

# Change background color to "lightblue" and grid color to "white"
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="lightblue", gridColor="white")

# Change plot fill color
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="white", fill=&amp;#39;#FFAAD4&amp;#39;)

# remove grid; remove top and right borders around the plot;
# change  axis lines
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="white", fill=&amp;#39;#FFAAD4&amp;#39;,
                removePanelGrid=TRUE,removePanelBorder=TRUE,
                axisLine=c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-background-color1.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-background-color2.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-background-color3.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-background-color4.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="163.2" /></p>
</div>
<div id="change-violin-plot-color-according-to-the-group" class="section level3">
<h3>Change violin plot color according to the group</h3>
<p><span class="warning">Colors can be specified as a hexadecimal RGB triplet, such as <code>"#FFCC00"</code> or by names (e.g : <code>"red"</code> ). You can also use other color scales, such as ones taken from the RColorBrewer package. The different <a href="https://www.sthda.com/english/english/wiki/colors-in-r">color systems</a> available in R have been described in detail <a href="https://www.sthda.com/english/english/wiki/colors-in-r">here</a>.<span></p>
<p><span class="success">To change <strong>violin plot</strong> color according to the group, you have to specify the name of the data column containing the groups using the argument <code>groupName</code>. Use the argument <code>groupColors</code>, to specify colors by <code>hexadecimal</code> code or by <code>name</code>. In this case, the length of groupColors should be the same as the number of the groups. Use the argument <code>brewerPalette</code>, to specify colors using <code>RColorBrewer</code>palette.</span></p>
<pre class="r"><code># Color the violin plot accoording to the groupName "dose"
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                   groupName=&amp;#39;dose&amp;#39;)

# Change group colors using hexadecimal colors
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        groupName=&amp;#39;dose&amp;#39;, 
        groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;))

# Change group colors using brewer palette: "Paired"
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, 
        groupName=&amp;#39;dose&amp;#39;, brewerPalette="Paired")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-violin-plot-color1.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-violin-plot-color2.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-violin-plot-color3.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="240" /></p>
<br/>
<div class="block">
<p>Color can also be changed by using names as follow :</p>
<pre class="r"><code># Change group colors using color names
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, 
        groupName=&amp;#39;dose&amp;#39;,
        groupColors=c(&amp;#39;aquamarine3&amp;#39;,&amp;#39;chartreuse1&amp;#39;,&amp;#39;goldenrod1&amp;#39;))</code></pre>
</div>
<p><br/></p>
</div>
</div>
<div id="legend" class="section level2">
<h2>Legend</h2>
<div id="legend-position" class="section level3">
<h3>Legend position</h3>
<pre class="r"><code># Change the legend position to "top" 
  # (possible values: "left","top", "right", "bottom")
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, 
          groupName=&amp;#39;dose&amp;#39;, legendPosition="top")

# legendPosition can be also a numeric vector c(x, y)
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        groupName=&amp;#39;dose&amp;#39;, legendPosition=c(0.8,0.2))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-legend-position1.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-legend-position2.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="240" /></p>
<p><span class="warning">It is also possible to position the legend inside the plotting area. You have to indicate the x, y coordinates of legend box. x and y values must be between 0 and 1. <code>c(0,0)</code> corresponds to <code>"bottom left"</code> and <code>c(1,1)</code> corresponds to <code>"top right"</code> position.</span></p>
</div>
<div id="legend-background-color-title-and-text-font-styles" class="section level3">
<h3>Legend background color, title and text font styles</h3>
<pre class="r"><code># Change legend background color, title and text font styles
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
    groupName=&amp;#39;dose&amp;#39;,
    # legendTitleFont=c(size, style, color)
    legendTitle="Dose (mg)", legendTitleFont=c(10, "bold", "blue"),
    #legendTextFont=c(size, style, color)
    legendTextFont=c(10, "bold.italic", "red"),
    # legendBackground: c(fill, lineSize, lineType, lineColor)
    legendBackground=c("lightblue", 0.5, "solid", "darkblue" )
    )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-legend-background-and-title.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="288" /></p>
</div>
<div id="change-the-order-of-items-in-the-legend-remove-plot-legend" class="section level3">
<h3>Change the order of items in the legend, remove plot legend</h3>
<pre class="r"><code># Change the order of items in the legend
 # legendItemOrder : character vector indicating 
# the order of items in the legends.
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        groupName=&amp;#39;dose&amp;#39;,
        legendItemOrder=c("2", "1", "0.5"))

# Remove plot legend
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        groupName=&amp;#39;dose&amp;#39;, showLegend=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-legend-item-order1.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-legend-item-order2.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="axis-scales" class="section level3">
<h3>Axis scales</h3>
<p>Possible values for y axis scale are “none”, “log2” and log10. Default value is “none”.</p>
<pre class="r"><code># Change y axis limit
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                groupName=&amp;#39;dose&amp;#39;, ylim=c(0,50))

# y Log scale. Possible values="none", "log2" and "log10"
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                groupName=&amp;#39;dose&amp;#39;, yScale="log2")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-axis-scale1.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-axis-scale2.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="240" /></p>
</div>
</div>
<div id="create-a-customized-plots-with-few-r-code" class="section level2">
<h2>Create a customized plots with few R code</h2>
<pre class="r"><code># Customized violinplot with centered dot plot
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, 
    groupName=&amp;#39;dose&amp;#39;,
    groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;), showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose",
    addDot=TRUE, dotSize=1)

#Remove grid; Remove Top and right border around the plot
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
    groupName=&amp;#39;dose&amp;#39;,
    groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;), showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose",
    addDot=TRUE, dotSize=1,
    removePanelGrid=TRUE,removePanelBorder=TRUE,
    axisLine=c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-customized-plot1.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-customized-plot2.png" title="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 violin plot : tutorial on how to use ggplot2.violinplot function to easily make a violin plot using ggplot2 and R statistical software" width="240" /></p>
</div>
</div>
<div id="violin-plot-with-multiple-groups" class="section level1">
<h1>Violin plot with multiple groups</h1>
<p><span class="blue">The data format is:</span></p>
<pre><code>##     len supp dose
## 1   4.2   VC  0.5
## 2  11.5   VC  0.5
## 3   7.3   VC  0.5
## 11 16.5   VC  1.0
## 12 16.5   VC  1.0
## 13 15.2   VC  1.0
## 14 17.3   VC  1.0
## 15 22.5   VC  1.0
## 21 23.6   VC  2.0
## 22 18.5   VC  2.0
## 23 33.9   VC  2.0
## 24 25.5   VC  2.0
## 31 15.2   OJ  0.5
## 32 21.5   OJ  0.5
## 33 17.6   OJ  0.5
## 34  9.7   OJ  0.5
## 41 19.7   OJ  1.0
## 42 23.3   OJ  1.0
## 43 23.6   OJ  1.0
## 44 26.4   OJ  1.0
## 51 25.5   OJ  2.0
## 52 26.4   OJ  2.0
## 53 22.4   OJ  2.0
## 54 24.5   OJ  2.0</code></pre>
<pre class="r"><code># plot of variable &amp;#39;len&amp;#39; by xName &amp;#39;dose&amp;#39;. The plot is colored by the groupName &amp;#39;supp&amp;#39;
# position = interval between box plot of the same group
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
    groupName=&amp;#39;supp&amp;#39;, position=position_dodge(0.8), 
    backgroundColor="white", groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;),
    legendPosition="top")  

# add dots
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, 
    groupName=&amp;#39;supp&amp;#39;, position=position_dodge(0.8),
    backgroundColor="white", groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;),
    addDot=TRUE, dotSize=1,legendPosition="top") </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-multiple-groups1.png" title="Violin plot with multiple groups" alt="Violin plot with multiple groups" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-multiple-groups2.png" title="Violin plot with multiple groups" alt="Violin plot with multiple groups" width="240" /></p>
</div>
<div id="facet-split-a-plot-into-a-matrix-of-panels" class="section level1">
<h1>Facet : split a plot into a matrix of panels</h1>
<p>The facet approach splits a plot into a matrix of panels. Each panel shows a different subset of the data.</p>
<div id="faceting-with-one-variable" class="section level2">
<h2>Faceting with one variable</h2>
<pre class="r"><code># Facet according to the supp variable
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, 
        groupName=&amp;#39;supp&amp;#39;, legendPosition="top",
        faceting=TRUE, facetingVarNames="supp") 

# Change the direction. possible values are "vertical", horizontal".
# Default is vertical.
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        groupName=&amp;#39;supp&amp;#39;, legendPosition="top",
        faceting=TRUE, facetingVarNames="supp",
        facetingDirection="horizontal") </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-facet-with-one-variable1.png" title="ggplot2 violin plot and facet approch, one variable" alt="ggplot2 violin plot and facet approch, one variable" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-facet-with-one-variable2.png" title="ggplot2 violin plot and facet approch, one variable" alt="ggplot2 violin plot and facet approch, one variable" width="240" /></p>
</div>
<div id="facet-with-two-variables" class="section level2">
<h2>Facet with two variables</h2>
<pre class="r"><code># Facet by two variables: dose and supp.
# Rows are dose and columns are supp
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
    groupName=&amp;#39;supp&amp;#39;, legendPosition="top",
    faceting=TRUE, facetingVarNames=c("dose","supp"))

# Facet by two variables: reverse the order of the 2 variables
# Rows are supp and columns are dose
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
    groupName=&amp;#39;supp&amp;#39;, legendPosition="top",
    faceting=TRUE, facetingVarNames=c("supp", "dose"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-facet-with-two-variables1.png" title="ggplot2 vilolin plot and facet approch, two variables" alt="ggplot2 vilolin plot and facet approch, two variables" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-facet-with-two-variables2.png" title="ggplot2 vilolin plot and facet approch, two variables" alt="ggplot2 vilolin plot and facet approch, two variables" width="240" /></p>
</div>
<div id="facet-scales" class="section level2">
<h2>Facet scales</h2>
<p>By default, all the panels have the same scale (<code>facetingScales="fixed"</code>). They can be made independent, by setting scales to <code>free</code>, <code>free_x</code>, or <code>free_y</code>.</p>
<pre class="r"><code># Facet with free scales
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
            groupName=&amp;#39;supp&amp;#39;, legendPosition="top",
            faceting=TRUE, facetingVarNames=c("dose", "supp"),
            facetingScales="free")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-facet-free-scale.png" title="ggplot2 violin plot and facet approch, facet scale" alt="ggplot2 violin plot and facet approch, facet scale" width="259.2" /></p>
<p><span class="success">As you can see in the above plot, y axis have different scales in the different panels.</span></p>
</div>
<div id="facet-label-apperance" class="section level2">
<h2>Facet label apperance</h2>
<pre class="r"><code># Change facet text font
# Possible values for the font style:&amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
        legendPosition="top",
        faceting=TRUE, facetingVarNames=c("dose","supp"),
        facetingFont=c(12, &amp;#39;bold.italic&amp;#39;, "red"))

# Change the apperance of the rectangle around facet label
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
        legendPosition="top",
        faceting=TRUE, facetingVarNames=c("dose","supp"),
        facetingRect=list(background="white", lineType="solid",
                          lineColor="black", lineSize=1.5)
        )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-facet-label-apperance1.png" title="ggplot2 violin plot and facet approch, facet label" alt="ggplot2 violin plot and facet approch, facet label" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-violin-plot-facet-label-apperance2.png" title="ggplot2 violin plot and facet approch, facet label" alt="ggplot2 violin plot and facet approch, facet label" width="240" /></p>
</div>
</div>
<div id="ggplot2.violinplot-function" class="section level1">
<h1>ggplot2.violinplot function</h1>
<div id="description" class="section level2">
<h2>Description</h2>
<p>Plot easily a violin plot plot with R package <strong>easyGgplot2</strong>.</p>
</div>
<div id="usage" class="section level2">
<h2>usage</h2>
<pre class="r"><code>ggplot2.violinplot(data, xName=NULL, yName=NULL, groupName=NULL,
        addMean=FALSE, meanPointShape=23, meanPointSize=4,
        meanPointColor="black", meanPointFill="blue",
        addDot=FALSE, dotSize=1, dotPosition=c("center", "jitter"),
        jitter=0.2, groupColors=NULL, brewerPalette=NULL,...)</code></pre>
</div>
<div id="arguments" class="section level2">
<h2>Arguments</h2>
<table>
<thead>
<tr class="header">
<th align="left">Arguments</th>
<th align="left">Descriptions</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>data</strong></td>
<td align="left">data.frame or a numeric vector. Columns are variables and rows are observations.</td>
</tr>
<tr class="even">
<td align="left"><strong>xName</strong></td>
<td align="left">The name of column containing x variable (i.e groups). Default value is NULL.</td>
</tr>
<tr class="odd">
<td align="left"><strong>yName</strong></td>
<td align="left">The name of column containing y variable. If yName=NULL, data should be a numeric vector.</td>
</tr>
<tr class="even">
<td align="left"><strong>groupName</strong></td>
<td align="left">The name of column containing group variable. This variable is used to color plot according to the group.</td>
</tr>
<tr class="odd">
<td align="left"><strong>addMean</strong></td>
<td align="left">if TRUE, the mean point is added on the plot for each group. Default value is FALSE.</td>
</tr>
<tr class="even">
<td align="left"><strong>meanPointShape, meanPointSize</strong></td>
<td align="left">The shape and size of mean point.</td>
</tr>
<tr class="odd">
<td align="left"><strong>meanPointColor</strong></td>
<td align="left">border color of the mean point. Default value is “black”.</td>
</tr>
<tr class="even">
<td align="left"><strong>meanPointFill</strong></td>
<td align="left">Fill color of mean point. This parameter is used only when meanPointShape=21 to 25. Default value is “blue”</td>
</tr>
<tr class="odd">
<td align="left"><strong>addDot</strong></td>
<td align="left">if TRUE, dotplot is added on the violinplot. Default value is FALSE.</td>
</tr>
<tr class="even">
<td align="left"><strong>dotSize</strong></td>
<td align="left">The size of dots.</td>
</tr>
<tr class="odd">
<td align="left"><strong>dotPosition</strong></td>
<td align="left">Possible values are “center” and “jitter”. Default value is “center”.</td>
</tr>
<tr class="even">
<td align="left"><strong>jitter</strong></td>
<td align="left">Degree of jitter in x direction. Default value is 0.2.</td>
</tr>
<tr class="odd">
<td align="left"><strong>groupColors</strong></td>
<td align="left">Color of groups. groupColors should have the same length as groups.</td>
</tr>
<tr class="even">
<td align="left"><strong>brewerPalette</strong></td>
<td align="left">This can be also used to indicate group colors. In this case the parameter groupColors should be NULL. e.g: brewerPalette=“Paired”.</td>
</tr>
<tr class="odd">
<td align="left"><strong>….</strong></td>
<td align="left">Other arguments passed on to ggplot2.customize custom function or to geom_dotplot and to geom_violin functions from ggplot2 package.</td>
</tr>
</tbody>
</table>
<p><span class="warning">The other arguments which can be used are described at this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2 customize</a>. They are used to customize the plot (axis, title, background, color, legend, ….) generated <strong>using ggplot2</strong> or <strong>easyGgplot2</strong> R package.</span></p>
</div>
<div id="examples" class="section level2">
<h2>Examples</h2>
<pre class="r"><code>df <- ToothGrowth
ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                mainTitle="Plot of length according\n to the dose",
                xtitle="Dose (mg)", ytitle="Length")

# Or use this
plot<-ggplot2.violinplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;)
plot<-ggplot2.customize(plot, mainTitle="Plot of length according\n to the dose",
                        xtitle="Dose (mg)", ytitle="Length")
print(plot)</code></pre>
<p><br/></p>
</div>
</div>
<div id="easy-ggplot2-ebook" class="section level1">
<h1>Easy ggplot2 ebook</h1>
<p><span class="success">Note that an eBook is available on <strong>easyGgplot2</strong> package <a href="https://www.sthda.com/english/english/download/download-4+easy-ggplot2-book.php">here</a>.</span></p>
<div class="block">
<p>By Alboukadel Kassambara</p>
<p>Copyright 2014 Alboukadel Kassambara. All rights reserved.</p>
<p>Published by STHDA (<a href="https://www.sthda.com/english">https://www.sthda.com/english</a>).</p>
<p>September 2014 : First edition.</p>
<p><strong>Licence</strong> : This document is under creative commons licence (<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">http://creativecommons.org/licenses/by-nc-sa/3.0/</a>).</p>
<p><strong>Contact</strong> : Alboukadel Kassambara <a href="mailto:alboukadel.kassambara@gmail.com">alboukadel.kassambara@gmail.com</a></p>
</div>
<p><br/></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning">This analysis was performed using R (ver. 3.1.0), easyGgplot2 (ver 1.0.0) and ggplot2 (ver 1.0.0).</span></p>
<ul>
<li><a href="http://docs.ggplot2.org/current/">ggplot2 online documentation</a></li>
<li><a href="http://www.cookbook-r.com/Graphs/">Cookbook for R</a></li>
</ul>
</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 Feb 2015 21:17:17 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[ggplot2 dot plot : Easy function for making a dot plot]]></title>
			<link>https://www.sthda.com/english/wiki/ggplot2-dot-plot-easy-function-for-making-a-dot-plot</link>
			<guid>https://www.sthda.com/english/wiki/ggplot2-dot-plot-easy-function-for-making-a-dot-plot</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#install-and-load-easyggplot2-package">Install and load easyGgplot2 package</a></li>
<li><a href="#data-format">Data format</a></li>
<li><a href="#basic-dot-plot">Basic dot plot</a></li>
<li><a href="#dot-plot-with-mean-point">Dot plot with mean point</a></li>
<li><a href="#customize-your-dot-plot">Customize your dot plot</a><ul>
<li><a href="#parameters">Parameters</a></li>
<li><a href="#main-title-and-axis-labels">Main title and axis labels</a></li>
<li><a href="#axis-ticks">Axis ticks</a></li>
<li><a href="#background-and-colors">Background and colors</a><ul>
<li><a href="#change-dot-plot-background-and-fill-colors">Change dot plot background and fill colors</a></li>
<li><a href="#change-dot-plot-color-according-to-the-group">Change dot plot color according to the group</a></li>
</ul></li>
<li><a href="#legend">Legend</a><ul>
<li><a href="#legend-position">Legend position</a></li>
<li><a href="#legend-background-color-title-and-text-font-styles">Legend background color, title and text font styles</a></li>
<li><a href="#change-the-order-of-items-in-the-legend-remove-plot-legend">Change the order of items in the legend, remove plot legend</a></li>
</ul></li>
<li><a href="#axis-scales">Axis scales</a></li>
<li><a href="#create-a-customized-plots-with-few-r-code">Create a customized plots with few R code</a></li>
</ul></li>
<li><a href="#dot-plot-with-multiple-groups">Dot plot with multiple groups</a></li>
<li><a href="#facet-split-a-plot-into-a-matrix-of-panels">Facet : split a plot into a matrix of panels</a><ul>
<li><a href="#facet-with-one-variable">Facet with one variable</a></li>
<li><a href="#facet-with-two-variables">Facet with two variables</a></li>
<li><a href="#facet-scales">Facet scales</a></li>
<li><a href="#facet-label-apperance">Facet label apperance</a></li>
</ul></li>
<li><a href="#ggplot2.dotplot-function">ggplot2.dotplot function</a><ul>
<li><a href="#description">Description</a></li>
<li><a href="#usage">usage</a></li>
<li><a href="#arguments">Arguments</a></li>
<li><a href="#examples">Examples</a></li>
</ul></li>
<li><a href="#easy-ggplot2-ebook">Easy ggplot2 ebook</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<div id="introduction" class="section level1">
<h1>Introduction</h1>
<p><strong>ggplot2.dotplot</strong> is an easy to use function for <strong>making a dot plot</strong> with <strong>R statistical software</strong> using <strong>ggplot2</strong> package. The aim of this <strong>tutorial</strong>, is to show you how to make a <strong>dot plot</strong> and to personalize the different graphical parameters including <strong>main title</strong>, <strong>axis labels</strong>, <strong>legend</strong>, <strong>background</strong> and <strong>colors</strong>. <strong>ggplot2.dotplot</strong> function is from <a href="https://www.sthda.com/english/english/wiki/easyggplot2"><strong>easyGgplot2</strong></a> R package. An R script is available in the next section to install the package.</p>
<p>At the end of this <strong>tutorial</strong> you will be able to draw, with few R code, the following plot :</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-demo.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="336" /></p>

<p><span class="warning"><strong>ggplot2.dotplot</strong> function is described in detail at the end of this document.</span></p>
</div>
<div id="install-and-load-easyggplot2-package" class="section level1">
<h1>Install and load easyGgplot2 package</h1>
<p><strong>easyGgplot2</strong> R package can be installed as follow :</p>
<pre class="r"><code>install.packages("devtools")
library(devtools)
install_github("easyGgplot2", "kassambara")</code></pre>
<p>Load the package using this R code :</p>
<pre class="r"><code>library(easyGgplot2)</code></pre>
</div>
<div id="data-format" class="section level1">
<h1>Data format</h1>
<p><span class="success">The data must be a numeric vector or a data.frame (columns are variables and rows are observations).</span></p>
<p>ToothGrowth data is used in the following examples.</p>
<pre class="r"><code># create a numeric vector
numVector<-rnorm(100)
head(numVector)</code></pre>
<pre><code>## [1]  1.2768 -1.6126 -0.1056  0.4091  0.8999 -0.7300</code></pre>
<pre class="r"><code># data.frame
df <- ToothGrowth
head(df)</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>
<br/>

<div class="block">
<p>ToothGrowth describes the effect of Vitamin C on Tooth growth in Guinea pigs. The response is the length (len) of teeth in each of 10 guinea pigs at each of three dose levels of Vitamin C (0.5, 1, and 2 mg) with each of two delivery methods (orange juice or ascorbic acid).</p>
The data is a data frame with 60 observations on 3 variables.
* [,1] len numeric Tooth length.
* [,2] supp factor Supplement type (VC or OJ).
* [,3] dose numeric Dose in milligrams.

</div>
<p><br/></p>
</div>
<div id="basic-dot-plot" class="section level1">
<h1>Basic dot plot</h1>
<pre class="r"><code># Dot plot from a single numeric vector 
ggplot2.dotplot(data=numVector)

# Basic dot plot from the vector "len"
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;)

# change dotsize and stack ratio
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, 
                stackratio=1.5, dotsize=1.2)

# Change the orientation: Horizontal dot plot
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                orientation="horizontal")

# Dot plot with box plot
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                addBoxplot=TRUE)

# dot plot with notched box plot
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                addBoxplot=TRUE,notch=TRUE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-basic-dot-plot1.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-basic-dot-plot2.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-basic-dot-plot3.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-basic-dot-plot4.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-basic-dot-plot5.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-basic-dot-plot6.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="163.2" /></p>
<p><span class="warning"> <strong>notch</strong>: If TRUE, make a notched box plot. The notch displays a confidence interval around the median which is normally based on the median +/- 1.57 x IQR/sqrt of n. Notches are used to compare groups; if the notches of two boxes do not overlap, this is strong evidence that the medians differ. </span></p>
</div>
<div id="dot-plot-with-mean-point" class="section level1">
<h1>Dot plot with mean point</h1>
<p>Each dot represents one observation and the mean point corresponds to the mean value of the observations in a given group.</p>
<pre class="r"><code># Dot plot with mean point
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        addMean=TRUE, meanPointShape=23, meanPointSize=4,
        meanPointColor="black", meanPointFill="blue")

#Change the dot plot border color
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                colour="red")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-dot-plot-with-mean1.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-dot-plot-with-mean2.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="customize-your-dot-plot" class="section level1">
<h1>Customize your dot plot</h1>
<div id="parameters" class="section level2">
<h2>Parameters</h2>
<p>The arguments that can be used to customize x and y axis are listed below :</p>
<table>
<thead>
<tr class="header">
<th align="left">Parameters</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>mainTitle</strong></td>
<td align="left">the title of the plot</td>
</tr>
<tr class="even">
<td align="left"><strong>mainTitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style (“italic”, “bold”, “bold.italic”) and the color of x and y axis titles. Default value is: mainTitleFont=c(14, “bold”, “black”).</td>
</tr>
<tr class="odd">
<td align="left"><strong>xShowTitle, yShowTitle</strong></td>
<td align="left">if TRUE, x and y axis titles will be shown. Set the value to FALSE to hide axis labels. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtitle, ytitle</strong></td>
<td align="left">x and y axis labels. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xtitleFont, ytitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis titles. Possible values for the <strong>style</strong>:“plain”, “italic”, “bold”, “bold.italic”. Color can be specified as an hexadecimal code (e.g: “#FFCC00”) or by the name (e.g : “red”, “green”). Default values are <code>xtitleFont=c(14,"bold", "black"), ytitleFont=c(14,"bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xlim, ylim</strong></td>
<td align="left">limit for the x and y axis. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xScale, yScale</strong></td>
<td align="left">x and y axis scales. Possible values : c(“none”, “log2”, “log10”). e.g: yScale=“log2”. Default values are <code>NULL</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xShowTickLabel, yShowTickLabel</strong></td>
<td align="left">if TRUE, x and y axis tick mark labels will be shown. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xTickLabelFont, yTickLabelFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis tick label fonts. Default value are <code>xTickLabelFont=c(12, "bold", "black"), yTickLabelFont=c(12, "bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtickLabelRotation, ytickLabelRotation</strong></td>
<td align="left">Rotation angle of x and y axis tick labels. Default value are <code>0</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>hideAxisTicks</strong></td>
<td align="left">if TRUE, x and y axis ticks are hidden. Default value is <code>FALSE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>axisLine</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the line type and the color of axis lines. Default value is <code>c(0.5, "solid", "#E5E5E5")</code>.</td>
</tr>
</tbody>
</table>
<p>For more details follow this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2.customize</a>.</p>
</div>
<div id="main-title-and-axis-labels" class="section level2">
<h2>Main title and axis labels</h2>
<pre class="r"><code># Change main title and axis titles
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                mainTitle="Plot of length \n by dose",
                xtitle="Dose (mg)", ytitle="Length")

# Customize title styles. Possible values for the font style :
  # &amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                xtitle="Dose (mg)", ytitle="Length",
                mainTitle="Plot of length \n by dose",
                mainTitleFont=c(14,"bold.italic", "red"),
                xtitleFont=c(14,"bold", "#993333"),
                ytitleFont=c(14,"bold", "#993333"))

# Hide x an y axis titles
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                xShowTitle=FALSE, yShowTitle=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-main-title-and-axis-labels1.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-main-title-and-axis-labels2.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-main-title-and-axis-labels3.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="163.2" /></p>
</div>
<div id="axis-ticks" class="section level2">
<h2>Axis ticks</h2>
<pre class="r"><code># Axis ticks labels and orientaion
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                xShowTitle=FALSE, yShowTitle=FALSE,
                xTickLabelFont=c(14,"bold", "#993333"),
                yTickLabelFont=c(14,"bold", "#993333"),
                xtickLabelRotation=45, ytickLabelRotation=45)

# Hide axis tick labels
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                xShowTitle=FALSE, yShowTitle=FALSE,
                xShowTickLabel=FALSE, yShowTickLabel=FALSE)

# Hide axis ticks
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                xShowTitle=FALSE, yShowTitle=FALSE,
                xShowTickLabel=FALSE,yShowTickLabel=FALSE,
                hideAxisTicks=TRUE)

# AxisLine : a vector of length 3 indicating the size,
  #the line type and the color of axis lines
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                axisLine=c(1, "solid", "darkblue"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-axis-ticks1.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-axis-ticks2.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-axis-ticks3.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-axis-ticks4.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="163.2" /></p>
</div>
<div id="background-and-colors" class="section level2">
<h2>Background and colors</h2>
<div id="change-dot-plot-background-and-fill-colors" class="section level3">
<h3>Change dot plot background and fill colors</h3>
<pre class="r"><code># change background color to "white". Default is "gray"
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="white")

# change background color to "lightblue" and grid color to "white"
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="lightblue", gridColor="white")

# Change plot fill color
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="white", fill=&amp;#39;#FFAAD4&amp;#39;)

# remove grid; remove top and right borders around the plot;
# change  axis lines
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="white", fill=&amp;#39;#FFAAD4&amp;#39;,
                removePanelGrid=TRUE,removePanelBorder=TRUE,
                axisLine=c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-background-color1.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-background-color2.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-background-color3.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-background-color4.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="change-dot-plot-color-according-to-the-group" class="section level3">
<h3>Change dot plot color according to the group</h3>
<p><span class="warning">Colors can be specified as a hexadecimal RGB triplet, such as <code>"#FFCC00"</code> or by names (e.g : <code>"red"</code> ). You can also use other color scales, such as ones taken from the RColorBrewer package. The different <a href="https://www.sthda.com/english/english/wiki/colors-in-r">color systems</a> available in R have been described in detail <a href="https://www.sthda.com/english/english/wiki/colors-in-r">here</a>.<span></p>
<p><span class="success">To change <strong>dot plot</strong> color according to the group, you have to specify the name of the data column containing the groups using the argument <code>groupName</code>. Use the argument <code>groupColors</code>, to specify colors by <code>hexadecimal</code> code or by <code>name</code>. In this case, the length of groupColors should be the same as the number of the groups. Use the argument <code>brewerPalette</code>, to specify colors using <code>RColorBrewer</code>palette.</span></p>
<pre class="r"><code># Color the dot plot accoording to the groupName "dose"
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;)

#Change group colors using hexadecimal colors
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;))

#Change group colors using brewer palette: "Paired"
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                brewerPalette="Paired")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-dot-plot-color1.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-dot-plot-color2.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-dot-plot-color3.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /></p>
<br/>
<div class="block">
<p>Color can also be changed by using names as follow :</p>
<pre class="r"><code>#Change group colors using color names
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
       groupName=&amp;#39;dose&amp;#39;,
       groupColors=c(&amp;#39;aquamarine3&amp;#39;,&amp;#39;chartreuse1&amp;#39;,&amp;#39;goldenrod1&amp;#39;))</code></pre>
</div>
<p><br/></p>
</div>
</div>
<div id="legend" class="section level2">
<h2>Legend</h2>
<div id="legend-position" class="section level3">
<h3>Legend position</h3>
<pre class="r"><code># Change the legend position to "top" 
  # (possible values: "left","top", "right", "bottom")
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                legendPosition="top")

# legendPosition can be also a numeric vector c(x, y)
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                legendPosition=c(0.8,0.2))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-legend-position1.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-legend-position2.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /></p>
<p><span class="warning">It is also possible to position the legend inside the plotting area. You have to indicate the x, y coordinates of legend box. x and y values must be between 0 and 1. <code>c(0,0)</code> corresponds to <code>"bottom left"</code> and <code>c(1,1)</code> corresponds to <code>"top right"</code> position.</span></p>
</div>
<div id="legend-background-color-title-and-text-font-styles" class="section level3">
<h3>Legend background color, title and text font styles</h3>
<pre class="r"><code># Change legend background color, title and text font styles
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
        # legendTitleFont=c(size, style, color)
        legendTitle="Dose (mg)",
        legendTitleFont=c(10, "bold", "blue"),
        #legendTextFont=c(size, style, color)
        legendTextFont=c(10, "bold.italic", "red"),
        # legendBackground: c(fill, lineSize, lineType, lineColor)
        legendBackground=c("lightblue", 0.5, "solid", "darkblue" )
        )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-legend-background-and-title.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="288" /></p>
</div>
<div id="change-the-order-of-items-in-the-legend-remove-plot-legend" class="section level3">
<h3>Change the order of items in the legend, remove plot legend</h3>
<pre class="r"><code># Change the order of items in the legend
 # legendItemOrder : character vector indicating 
# the order of items in the legends.
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                legendItemOrder=c("2", "1", "0.5"))
    
# Remove plot legend
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                showLegend=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-legend-item-order1.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-legend-item-order2.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /></p>
</div>
</div>
<div id="axis-scales" class="section level2">
<h2>Axis scales</h2>
<p>Possible values for y axis scale are “none”, “log2” and log10. Default value is “none”.</p>
<pre class="r"><code># Change y axis limit
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                ylim=c(0,50))

# y Log scale. Possible values="none", "log2" and "log10"
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                yScale="log2")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-axis-scale1.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-axis-scale2.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="create-a-customized-plots-with-few-r-code" class="section level2">
<h2>Create a customized plots with few R code</h2>
<pre class="r"><code>#Customized dot plot
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
    groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;), showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose")

# Customized dot plot with notched box plot
# Remove grid; Remove Top and right border around the plot
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
    groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;), showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose",
    addBoxplot=TRUE, notch=TRUE,
    removePanelGrid=TRUE,removePanelBorder=TRUE,
    axisLine=c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-customized-plot-part1_1.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-customized-plot-part1_2.png" title="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" alt="r data visualization with ggplot2 dot plot : tutorial on how to use ggplot2.dotplot function for easily making a dot plot using ggplot2 and R statistical software" width="240" /></p>
<pre class="r"><code># Customized dot plot, add box plot, pink fill color.
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
    groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;), showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose",
    addBoxplot=TRUE, boxplotFill="pink")

# Customized dot plot, add box plot, 
#fill box plot accoording to the groups.
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
    groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;), showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose",
    addBoxplot=TRUE, boxplotFill=NULL)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-customized-plot-part2_1.png" title="ggplot2 dotplot" alt="ggplot2 dotplot" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-customized-plot-part2_2.png" title="ggplot2 dotplot" alt="ggplot2 dotplot" width="240" /></p>
<p><span class="warning"> By default, box plot fill color is “white”. To change the fill color with the argument <strong>groupColors</strong>, set boxplotFill value to <strong>NULL</strong>. </span></p>
</div>
</div>
<div id="dot-plot-with-multiple-groups" class="section level1">
<h1>Dot plot with multiple groups</h1>
<p><span class="blue">The data format is:</span></p>
<pre><code>##     len supp dose
## 1   4.2   VC  0.5
## 2  11.5   VC  0.5
## 3   7.3   VC  0.5
## 11 16.5   VC  1.0
## 12 16.5   VC  1.0
## 13 15.2   VC  1.0
## 14 17.3   VC  1.0
## 15 22.5   VC  1.0
## 21 23.6   VC  2.0
## 22 18.5   VC  2.0
## 23 33.9   VC  2.0
## 24 25.5   VC  2.0
## 31 15.2   OJ  0.5
## 32 21.5   OJ  0.5
## 33 17.6   OJ  0.5
## 34  9.7   OJ  0.5
## 41 19.7   OJ  1.0
## 42 23.3   OJ  1.0
## 43 23.6   OJ  1.0
## 44 26.4   OJ  1.0
## 51 25.5   OJ  2.0
## 52 26.4   OJ  2.0
## 53 22.4   OJ  2.0
## 54 24.5   OJ  2.0</code></pre>
<pre class="r"><code># plot of variable &amp;#39;len&amp;#39; by xName &amp;#39;dose&amp;#39;. The plot is colored by the groupName &amp;#39;supp&amp;#39;
# position = interval between dot plot of the same group
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
      position=position_dodge(0.8), 
      backgroundColor="white",groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;)
    )  
 
# Change the interval between dotplot of the same group : 
  # position=position_dodge(0); overlap
#add box plot
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
      position=position_dodge(0.0), 
      backgroundColor="white", groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;),
      addBoxplot=TRUE, boxplotFill="white")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-multiple-dot-plots1.png" title="Dot plot with multiple groups" alt="Dot plot with multiple groups" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-multiple-dot-plots2.png" title="Dot plot with multiple groups" alt="Dot plot with multiple groups" width="240" /></p>
</div>
<div id="facet-split-a-plot-into-a-matrix-of-panels" class="section level1">
<h1>Facet : split a plot into a matrix of panels</h1>
<p>The facet approach splits a plot into a matrix of panels. Each panel shows a different subset of the data.</p>
<div id="facet-with-one-variable" class="section level2">
<h2>Facet with one variable</h2>
<pre class="r"><code>#Facet according to the supp variable
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
      legendPosition="top",
      faceting=TRUE, facetingVarNames="supp") 

# Change the direction. possible values are "vertical", horizontal".
# default is vertical.
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
        legendPosition="top",
        faceting=TRUE, facetingVarNames="supp",
        facetingDirection="horizontal") </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-facet-with-one-variable1.png" title="ggplot2 dot plot and facet approch, one variable" alt="ggplot2 dot plot and facet approch, one variable" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-facet-with-one-variable2.png" title="ggplot2 dot plot and facet approch, one variable" alt="ggplot2 dot plot and facet approch, one variable" width="240" /></p>
</div>
<div id="facet-with-two-variables" class="section level2">
<h2>Facet with two variables</h2>
<pre class="r"><code># Facet by two variables: dose and supp.
# Rows are dose and columns are supp
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
          legendPosition="top", faceting=TRUE,
          facetingVarNames=c("dose","supp"))

# Facet by two variables: reverse the order of the 2 variables
# Rows are supp and columns are dose
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
        legendPosition="top", faceting=TRUE,
        facetingVarNames=c("supp", "dose"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-facet-with-two-variables1.png" title="ggplot2 dot plot and facet approch, two variables" alt="ggplot2 dot plot and facet approch, two variables" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-facet-with-two-variables2.png" title="ggplot2 dot plot and facet approch, two variables" alt="ggplot2 dot plot and facet approch, two variables" width="240" /></p>
</div>
<div id="facet-scales" class="section level2">
<h2>Facet scales</h2>
<p>By default, all the panels have the same scale (<code>facetingScales="fixed"</code>). They can be made independent, by setting scales to <code>free</code>, <code>free_x</code>, or <code>free_y</code>.</p>
<pre class="r"><code># Facet with free scales
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        groupName=&amp;#39;supp&amp;#39;, legendPosition="top",
        faceting=TRUE, facetingVarNames=c("dose", "supp"),
        facetingScales="free")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-facet-free-scale.png" title="ggplot2 dotplot and facet approch, free scale" alt="ggplot2 dotplot and facet approch, free scale" width="288" /></p>
<p><span class="success">As you can see in the above plot, y axis have different scales in the different panels.</span></p>
</div>
<div id="facet-label-apperance" class="section level2">
<h2>Facet label apperance</h2>
<pre class="r"><code># Change facet text font. Possible values for the font style:
  #&amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
        legendPosition="top",
        faceting=TRUE, facetingVarNames=c("dose","supp"),
        facetingFont=c(12, &amp;#39;bold.italic&amp;#39;, "red"))

# Change the apperance of the rectangle around facet label
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
            legendPosition="top",
            faceting=TRUE, facetingVarNames=c("dose","supp"),
            facetingRect=list(background="white", lineType="solid",
                              lineColor="black", lineSize=1.5)
            )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-facet-label-apperance1.png" title="ggplot2 dot plot and facet approch, facet label" alt="ggplot2 dot plot and facet approch, facet label" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-dot-plot-facet-label-apperance2.png" title="ggplot2 dot plot and facet approch, facet label" alt="ggplot2 dot plot and facet approch, facet label" width="240" /></p>
</div>
</div>
<div id="ggplot2.dotplot-function" class="section level1">
<h1>ggplot2.dotplot function</h1>
<div id="description" class="section level2">
<h2>Description</h2>
<p>Plot easily a dot plot plot with R package <strong>easyGgplot2</strong>.</p>
</div>
<div id="usage" class="section level2">
<h2>usage</h2>
<pre class="r"><code>ggplot2.dotplot(data, xName=NULL, yName=NULL, groupName=NULL,
          position=position_dodge(0.8),
          addMean=FALSE, meanPointShape=5, meanPointSize=4,
          meanPointColor="black", meanPointFill="blue",
          addBoxplot=FALSE, boxplotFill="white",
          boxplotColor="black", boxplotLineWeight=0.5,
          groupColors=NULL, brewerPalette=NULL,...)</code></pre>
</div>
<div id="arguments" class="section level2">
<h2>Arguments</h2>
<table>
<thead>
<tr class="header">
<th align="left">Arguments</th>
<th align="left">Descriptions</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>data</strong></td>
<td align="left">data.frame or a numeric vector. Columns are variables and rows are observations.</td>
</tr>
<tr class="even">
<td align="left"><strong>xName</strong></td>
<td align="left">The name of column containing x variable (i.e groups). Default value is NULL.</td>
</tr>
<tr class="odd">
<td align="left"><strong>yName</strong></td>
<td align="left">The name of column containing y variable. If yName=NULL, data should be a numeric vector.</td>
</tr>
<tr class="even">
<td align="left"><strong>groupName</strong></td>
<td align="left">The name of column containing group variable. This variable is used to color plot according to the group.</td>
</tr>
<tr class="odd">
<td align="left"><strong>position</strong></td>
<td align="left">The position adjustment to use for overlapping points. <strong>Default value is position_dodge(0.8)</strong>.</td>
</tr>
<tr class="even">
<td align="left"><strong>addMean</strong></td>
<td align="left">if TRUE, the mean point is added on the plot for each group. Default value is FALSE.</td>
</tr>
<tr class="odd">
<td align="left"><strong>meanPointShape, meanPointSize</strong></td>
<td align="left">The shape and size of mean point.</td>
</tr>
<tr class="even">
<td align="left"><strong>meanPointColor</strong></td>
<td align="left">border color of the mean point. Default value is “black”.</td>
</tr>
<tr class="odd">
<td align="left"><strong>meanPointFill</strong></td>
<td align="left">Fill color of mean point. This parameter is used only when meanPointShape=21 to 25. Default value is “blue”</td>
</tr>
<tr class="even">
<td align="left"><strong>addBoxplot</strong></td>
<td align="left">If TRUE, boxplot is added on the dotplot. Default value is FALSE.</td>
</tr>
<tr class="odd">
<td align="left"><strong>boxplotFill</strong></td>
<td align="left">Fill color of the boxplot. <b>Default value is white</b>.</td>
</tr>
<tr class="even">
<td align="left"><strong>boxplotColor</strong></td>
<td align="left">Boxplot line color. <b>Default value is black.</b></td>
</tr>
<tr class="odd">
<td align="left"><strong>boxplotLineWeight</strong></td>
<td align="left">Boxplot line weight. <b>Default value is 0.5.</b></td>
</tr>
<tr class="even">
<td align="left"><strong>groupColors</strong></td>
<td align="left">Color of groups. groupColors should have the same length as groups.</td>
</tr>
<tr class="odd">
<td align="left"><strong>brewerPalette</strong></td>
<td align="left">This can be also used to indicate group colors. In this case the parameter groupColors should be NULL. e.g: brewerPalette=“Paired”.</td>
</tr>
<tr class="even">
<td align="left"><strong>….</strong></td>
<td align="left">Other arguments passed on to ggplot2.customize custom function or to geom_dotplot functions from ggplot2 package.</td>
</tr>
</tbody>
</table>
<p><span class="warning">The other arguments which can be used are described at this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2 customize</a>. They are used to customize the plot (axis, title, background, color, legend, ….) generated <strong>using ggplot2</strong> or <strong>easyGgplot2</strong> R package.</span></p>
</div>
<div id="examples" class="section level2">
<h2>Examples</h2>
<pre class="r"><code>df <- ToothGrowth
ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                mainTitle="Plot of length according\n to the dose",
                xtitle="Dose (mg)", ytitle="Length")

#Or use this
plot<-ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;)
plot<-ggplot2.customize(plot, mainTitle="Plot of length according\n to the dose",
                        xtitle="Dose (mg)", ytitle="Length")
print(plot)</code></pre>
</div>
</div>
<div id="easy-ggplot2-ebook" class="section level1">
<h1>Easy ggplot2 ebook</h1>
<p><span class="success">Note that an eBook is available on <strong>easyGgplot2</strong> package <a href="https://www.sthda.com/english/english/download/download-4+easy-ggplot2-book.php">here</a>.</span></p>
<div class="block">
<p>By Alboukadel Kassambara</p>
<p>Copyright 2014 Alboukadel Kassambara. All rights reserved.</p>
<p>Published by STHDA (<a href="https://www.sthda.com/english">https://www.sthda.com/english</a>).</p>
<p>September 2014 : First edition.</p>
<p><strong>Licence</strong> : This document is under creative commons licence (<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">http://creativecommons.org/licenses/by-nc-sa/3.0/</a>).</p>
<p><strong>Contact</strong> : Alboukadel Kassambara <a href="mailto:alboukadel.kassambara@gmail.com">alboukadel.kassambara@gmail.com</a></p>
</div>
<p><br/></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning">This analysis was performed using R (ver. 3.1.0), easyGgplot2 (ver 1.0.0) and ggplot2 (ver 1.0.0).</span></p>
<ul>
<li><a href="http://docs.ggplot2.org/current/">ggplot2 online documentation</a></li>
<li><a href="http://www.cookbook-r.com/Graphs/">Cookbook for R</a></li>
</ul>
</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 Feb 2015 21:15:56 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[ggplot2.stripchart : Easy one dimensional scatter plot using ggplot2 and R software]]></title>
			<link>https://www.sthda.com/english/wiki/ggplot2-stripchart-easy-one-dimensional-scatter-plot-using-ggplot2-and-r-software</link>
			<guid>https://www.sthda.com/english/wiki/ggplot2-stripchart-easy-one-dimensional-scatter-plot-using-ggplot2-and-r-software</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#install-and-load-easyggplot2-package">Install and load easyGgplot2 package</a></li>
<li><a href="#data-format">Data format</a></li>
<li><a href="#basic-stripchart">Basic stripchart</a></li>
<li><a href="#stripchart-with-mean-point">Stripchart with mean point</a></li>
<li><a href="#change-the-stripchart-point-shape">Change the stripchart point shape</a></li>
<li><a href="#customize-your-stripchart">Customize your stripchart</a><ul>
<li><a href="#parameters">Parameters</a></li>
<li><a href="#main-title-and-axis-labels">Main title and axis labels</a></li>
<li><a href="#axis-ticks">Axis ticks</a></li>
<li><a href="#background-and-colors">Background and colors</a><ul>
<li><a href="#change-stripchart-background-and-fill-colors">Change stripchart background and fill colors</a></li>
<li><a href="#change-stripchart-color-according-to-the-group">Change stripchart color according to the group</a></li>
</ul></li>
<li><a href="#legend">Legend</a><ul>
<li><a href="#legend-position">Legend position</a></li>
<li><a href="#legend-background-color-title-and-text-font-styles">Legend background color, title and text font styles</a></li>
<li><a href="#change-the-order-of-items-in-the-legend-remove-plot-legend">Change the order of items in the legend, remove plot legend</a></li>
</ul></li>
<li><a href="#axis-scales">Axis scales</a></li>
<li><a href="#create-a-customized-plots-with-few-r-code">Create a customized plots with few R code</a></li>
</ul></li>
<li><a href="#stripchart-with-multiple-groups">Stripchart with multiple groups</a></li>
<li><a href="#facet-split-a-plot-into-a-matrix-of-pannels">Facet : split a plot into a matrix of pannels</a><ul>
<li><a href="#facet-with-one-variable">Facet with one variable</a></li>
<li><a href="#facet-with-two-variables">Facet with two variables</a></li>
<li><a href="#facet-scales">Facet scales</a></li>
<li><a href="#facet-label-apperance">Facet label apperance</a></li>
</ul></li>
<li><a href="#ggplot2.stripchart-function">ggplot2.stripchart function</a><ul>
<li><a href="#description">Description</a></li>
<li><a href="#usage">usage</a></li>
<li><a href="#arguments">Arguments</a></li>
<li><a href="#examples">Examples</a></li>
</ul></li>
<li><a href="#easy-ggplot2-ebook">Easy ggplot2 ebook</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<div id="introduction" class="section level1">
<h1>Introduction</h1>
<p><strong>ggplot2.stripchart</strong> is an easy to use function (from <a href="https://www.sthda.com/english/english/wiki/eayggplot2">easyGgplot2</a> package), to produce a stripchart using <strong>ggplot2</strong> plotting system and <strong>R software</strong>. <strong>Stripcharts</strong> are also known as one dimensional scatter plots (or dot plots). These <strong>plots</strong> are suitable compared to box plots when sample sizes are small.</p>
<p>The aim of this <strong>tutorial</strong> is to show you step by step, how to plot and customize a <strong>stripchart</strong> using ggplot2.stripchart function.</p>
<p>At the end of this tutorial you will be able to draw, with few R code, the following plots :</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-demo1.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-demo2.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /></p>

<p><span class="warning"><strong>ggplot2.stripchart</strong> function is described in detail at the end of this document.</span></p>
</div>
<div id="install-and-load-easyggplot2-package" class="section level1">
<h1>Install and load easyGgplot2 package</h1>
<p><strong>easyGgplot2</strong> R package can be installed as follow :</p>
<pre class="r"><code>install.packages("devtools")
library(devtools)
install_github("easyGgplot2", "kassambara")</code></pre>
<p>Load the package using this R code :</p>
<pre class="r"><code>library(easyGgplot2)</code></pre>
</div>
<div id="data-format" class="section level1">
<h1>Data format</h1>
<p><span class="success">The data must be a numeric vector or a data.frame (columns are variables and rows are observations).</span></p>
<p>ToothGrowth data is used in the following examples.</p>
<pre class="r"><code># create a numeric vector
numVector<-rnorm(100)
head(numVector)</code></pre>
<pre><code>## [1] -0.7958  0.1623  2.1102  0.5006  0.2491 -1.5663</code></pre>
<pre class="r"><code># data.frame
df <- ToothGrowth
head(df)</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>
<br/>

<div class="block">
<p>ToothGrowth describes the effect of Vitamin C on Tooth growth in Guinea pigs. The response is the length (len) of teeth in each of 10 guinea pigs at each of three dose levels of Vitamin C (0.5, 1, and 2 mg) with each of two delivery methods (orange juice or ascorbic acid).</p>
The data is a data frame with 60 observations on 3 variables.
* [,1] len numeric Tooth length.
* [,2] supp factor Supplement type (VC or OJ).
* [,3] dose numeric Dose in milligrams.

</div>
<p><br/></p>
</div>
<div id="basic-stripchart" class="section level1">
<h1>Basic stripchart</h1>
<pre class="r"><code># Stripchart from a single numeric vector 
ggplot2.stripchart(data=numVector)

# Basic stripchart from the vector "len"
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;)

#change dot size
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, 
                size=3)

# Change the orientation: Horizontal stripchart
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                orientation="horizontal")

# Stripchart with box plot
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                addBoxplot=TRUE)

# stripchart with notched box plot
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                addBoxplot=TRUE,notch=TRUE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-basic-stripchart1.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-basic-stripchart2.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-basic-stripchart3.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-basic-stripchart4.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-basic-stripchart5.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-basic-stripchart6.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="163.2" /></p>
<p><span class="warning"> <strong>notch</strong>: If TRUE, make a notched box plot. The notch displays a confidence interval around the median which is normally based on the median +/- 1.57 x IQR/sqrt of n. Notches are used to compare groups; if the notches of two boxes do not overlap, this is strong evidence that the medians differ. </span></p>
<p><span class="success">To change the size of dots, use the argument ‘size’ (e.g : size = 4)</span></p>
</div>
<div id="stripchart-with-mean-point" class="section level1">
<h1>Stripchart with mean point</h1>
<p>Each dot represents one observation and the mean point corresponds to the mean value of the observations in a given group.</p>
<pre class="r"><code># Stripchart with mean point
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
      addMean=TRUE, meanPointShape=23, meanPointSize=4,
      meanPointColor="black", meanPointFill="blue")

# Change the stripchart color
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                colour="red")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-stripchart-with-mean1.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-stripchart-with-mean2.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="change-the-stripchart-point-shape" class="section level1">
<h1>Change the stripchart point shape</h1>
<p><span class="warning">Different <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">point shapes</a> and <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">line types</a> can be used in the plot. By default, ggplot2 uses solid line type and circle shape.</span></p>
<ul>
<li>The different <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">point shapes</a> in R are described <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">here</a>.</li>
<li>The available <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">line types</a> are shown <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">here</a>.</li>
</ul>
<pre class="r"><code># Change point shape
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                shape=18)
# Change point shape
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                shape=17)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-line-type-and-point-shape1.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-line-type-and-point-shape2.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="customize-your-stripchart" class="section level1">
<h1>Customize your stripchart</h1>
<div id="parameters" class="section level2">
<h2>Parameters</h2>
<p>The arguments that can be used to customize x and y axis are listed below :</p>
<table>
<thead>
<tr class="header">
<th align="left">Parameters</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>mainTitle</strong></td>
<td align="left">the title of the plot</td>
</tr>
<tr class="even">
<td align="left"><strong>mainTitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style (“italic”, “bold”, “bold.italic”) and the color of x and y axis titles. Default value is: mainTitleFont=c(14, “bold”, “black”).</td>
</tr>
<tr class="odd">
<td align="left"><strong>xShowTitle, yShowTitle</strong></td>
<td align="left">if TRUE, x and y axis titles will be shown. Set the value to FALSE to hide axis labels. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtitle, ytitle</strong></td>
<td align="left">x and y axis labels. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xtitleFont, ytitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis titles. Possible values for the <strong>style</strong>:“plain”, “italic”, “bold”, “bold.italic”. Color can be specified as an hexadecimal code (e.g: “#FFCC00”) or by the name (e.g : “red”, “green”). Default values are <code>xtitleFont=c(14,"bold", "black"), ytitleFont=c(14,"bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xlim, ylim</strong></td>
<td align="left">limit for the x and y axis. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xScale, yScale</strong></td>
<td align="left">x and y axis scales. Possible values : c(“none”, “log2”, “log10”). e.g: yScale=“log2”. Default values are <code>NULL</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xShowTickLabel, yShowTickLabel</strong></td>
<td align="left">if TRUE, x and y axis tick mark labels will be shown. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xTickLabelFont, yTickLabelFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis tick label fonts. Default value are <code>xTickLabelFont=c(12, "bold", "black"), yTickLabelFont=c(12, "bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtickLabelRotation, ytickLabelRotation</strong></td>
<td align="left">Rotation angle of x and y axis tick labels. Default value are <code>0</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>hideAxisTicks</strong></td>
<td align="left">if TRUE, x and y axis ticks are hidden. Default value is <code>FALSE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>axisLine</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the line type and the color of axis lines. Default value is <code>c(0.5, "solid", "#E5E5E5")</code>.</td>
</tr>
</tbody>
</table>
<p>For more details follow this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2.customize</a>.</p>
</div>
<div id="main-title-and-axis-labels" class="section level2">
<h2>Main title and axis labels</h2>
<pre class="r"><code># Change main title and axis titles
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                mainTitle="Plot of length \n by dose",
                xtitle="Dose (mg)", ytitle="Length")

# Customize title styles. Possible values for the font style :
  # &amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                xtitle="Dose (mg)", ytitle="Length",
                mainTitle="Plot of length \n by dose",
                mainTitleFont=c(14,"bold.italic", "red"),
                xtitleFont=c(14,"bold", "#993333"),
                ytitleFont=c(14,"bold", "#993333"))

# Hide x an y axis titles
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                xShowTitle=FALSE, yShowTitle=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-main-title-and-axis-labels1.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-main-title-and-axis-labels2.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-main-title-and-axis-labels3.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="axis-ticks" class="section level2">
<h2>Axis ticks</h2>
<pre class="r"><code># Axis ticks labels and orientaion
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        xShowTitle=FALSE, yShowTitle=FALSE,
        xTickLabelFont=c(14,"bold", "#993333"),
        yTickLabelFont=c(14,"bold", "#993333"),
        xtickLabelRotation=45, ytickLabelRotation=45)

# Hide axis tick labels
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
      xShowTitle=FALSE, yShowTitle=FALSE,
      xShowTickLabel=FALSE, yShowTickLabel=FALSE)

# Hide axis ticks
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        xShowTitle=FALSE, yShowTitle=FALSE,
        xShowTickLabel=FALSE, yShowTickLabel=FALSE,
        hideAxisTicks=TRUE)

# AxisLine : a vector of length 3 indicating the size,
  #the line type and the color of axis lines
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, 
         axisLine=c(1, "solid", "darkblue"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-axis-ticks1.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-axis-ticks2.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-axis-ticks3.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-axis-ticks4.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="163.2" /></p>
</div>
<div id="background-and-colors" class="section level2">
<h2>Background and colors</h2>
<div id="change-stripchart-background-and-fill-colors" class="section level3">
<h3>Change stripchart background and fill colors</h3>
<pre class="r"><code># change background color to "white". Default is "gray"
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="white")

# Change background color to "lightblue" and grid color to "white"
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="lightblue", gridColor="white")

# Change plot fill color
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="white", fill=&amp;#39;#FFAAD4&amp;#39;)

# remove grid; remove top and right borders around the plot;
# change  axis lines
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="white", fill=&amp;#39;#FFAAD4&amp;#39;,
                removePanelGrid=TRUE,removePanelBorder=TRUE,
                axisLine=c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-background-color1.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-background-color2.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-background-color3.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-background-color4.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="163.2" /></p>
</div>
<div id="change-stripchart-color-according-to-the-group" class="section level3">
<h3>Change stripchart color according to the group</h3>
<p><span class="warning">Colors can be specified as a hexadecimal RGB triplet, such as <code>"#FFCC00"</code> or by names (e.g : <code>"red"</code> ). You can also use other color scales, such as ones taken from the RColorBrewer package. The different <a href="https://www.sthda.com/english/english/wiki/colors-in-r">color systems</a> available in R have been described in detail <a href="https://www.sthda.com/english/english/wiki/colors-in-r">here</a>.<span></p>
<p><span class="success">To change <strong>stripchart</strong> color according to the group, you have to specify the name of the data column containing the groups using the argument <code>groupName</code>. Use the argument <code>groupColors</code>, to specify colors by <code>hexadecimal</code> code or by <code>name</code>. In this case, the length of groupColors should be the same as the number of the groups. Use the argument <code>brewerPalette</code>, to specify colors using <code>RColorBrewer</code>palette.</span></p>
<pre class="r"><code># Color the stripchart accoording to the groupName "dose"
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        groupName=&amp;#39;dose&amp;#39;)

# Change group colors using hexadecimal colors
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        groupName=&amp;#39;dose&amp;#39;,
        groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;))

# Change group colors using brewer palette: "Paired"
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        groupName=&amp;#39;dose&amp;#39;,brewerPalette="Paired")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-stripchart-color1.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-stripchart-color2.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-stripchart-color3.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /></p>
<br/>
<div class="block">
<p>Color can also be changed by using names as follow :</p>
<pre class="r"><code># Change group colors using color names
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
      groupName=&amp;#39;dose&amp;#39;,
      groupColors=c(&amp;#39;aquamarine3&amp;#39;,&amp;#39;chartreuse1&amp;#39;,&amp;#39;goldenrod1&amp;#39;))</code></pre>
</div>
<p><br/></p>
</div>
</div>
<div id="legend" class="section level2">
<h2>Legend</h2>
<div id="legend-position" class="section level3">
<h3>Legend position</h3>
<pre class="r"><code># Change the legend position to "top" 
  # (possible values: "left","top", "right", "bottom")
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        groupName=&amp;#39;dose&amp;#39;, legendPosition="top")

# legendPosition can be also a numeric vector c(x, y)
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        groupName=&amp;#39;dose&amp;#39;, legendPosition=c(0.8,0.2))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-legend-position1.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-legend-position2.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /></p>
<p><span class="warning">It is also possible to position the legend inside the plotting area. You have to indicate the x, y coordinates of legend box. x and y values must be between 0 and 1. c(0,0) corresponds to <strong>“bottom left”</strong> and c(1,1) corresponds to <strong>“top right”</strong> position.</span></p>
</div>
<div id="legend-background-color-title-and-text-font-styles" class="section level3">
<h3>Legend background color, title and text font styles</h3>
<pre class="r"><code># Change legend background color, title and text font styles
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
    groupName=&amp;#39;dose&amp;#39;,
    #legendTitleFont=c(size, style, color)
    legendTitle="Dose (mg)", legendTitleFont=c(10, "bold", "blue"),
    #legendTextFont=c(size, style, color)
    legendTextFont=c(10, "bold.italic", "red"),
    #legendBackground: c(fill, lineSize, lineType, lineColor)
    legendBackground=c("lightblue", 0.5, "solid", "darkblue" )
    )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-legend-background-and-title.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="288" /></p>
</div>
<div id="change-the-order-of-items-in-the-legend-remove-plot-legend" class="section level3">
<h3>Change the order of items in the legend, remove plot legend</h3>
<pre class="r"><code># Change the order of items in the legend
 # legendItemOrder : character vector indicating 
# the order of items in the legends.
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
            groupName=&amp;#39;dose&amp;#39;,
            legendItemOrder=c("2", "1", "0.5"))

# Remove plot legend
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
              groupName=&amp;#39;dose&amp;#39;, showLegend=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-legend-item-order1.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-legend-item-order2.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /></p>
</div>
</div>
<div id="axis-scales" class="section level2">
<h2>Axis scales</h2>
<p>Possible values for y axis scale are “none”, “log2” and log10. Default value is “none”.</p>
<pre class="r"><code># Change y axis limit
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                groupName=&amp;#39;dose&amp;#39;, ylim=c(0,50))

# y Log scale. yScale="log2". 
# Possible value="none", "log2" and "log10"
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
              groupName=&amp;#39;dose&amp;#39;, yScale="log2")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-axis-scale1.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-axis-scale2.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="create-a-customized-plots-with-few-r-code" class="section level2">
<h2>Create a customized plots with few R code</h2>
<pre class="r"><code># Customized stripchart
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
    groupName=&amp;#39;dose&amp;#39;,
    groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;), showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose")

# Customized stripchart with notched box plot
# Remove grid; Remove Top and right border around the plot
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
    groupName=&amp;#39;dose&amp;#39;,
    groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;), showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose",
    addBoxplot=TRUE, notch=TRUE,
    removePanelGrid=TRUE,removePanelBorder=TRUE,
    axisLine=c(0.5, "solid", "black"))

# Customized stripchart, change point color, 
# fill box plot accoording to the groups
#Change the color of points to "black"
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
    groupName=&amp;#39;dose&amp;#39;,
    groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;), showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose",
    addBoxplot=TRUE, boxplotFill=NULL, notch=TRUE, colour="black")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-customized-plot-part1_1.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-customized-plot-part1_2.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-customized-plot-part1_3.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /></p>
<pre class="r"><code># Customized stripchart, add box plot, pink fill color.
# Change the color of points to "black"
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
    groupName=&amp;#39;dose&amp;#39;,
    groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;), showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose",
    addBoxplot=TRUE, boxplotFill="pink", colour="black")

# Customized stripchart, add box plot, 
#fill box plot accoording to the groups.
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
    groupName=&amp;#39;dose&amp;#39;,
    groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;),
    showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose",
    addBoxplot=TRUE, boxplotFill=NULL, colour="black")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-customized-plot-part2_1.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-customized-plot-part2_2.png" title="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" alt="Data visualization with ggplot2 stripchart : tutorial on how to use ggplot2.stripchart function to produce a one dimensional scatter plots (or dot plots) using ggplot2 and R statistical software" width="240" /></p>
<p><span class="warning">By default, box plot fill color is “white”. To change the fill color with the argument <strong>groupColors</strong>, set boxplotFill value to <strong>NULL</strong>. </span></p>
</div>
</div>
<div id="stripchart-with-multiple-groups" class="section level1">
<h1>Stripchart with multiple groups</h1>
<p><span class="blue">The data format is :</span></p>
<pre><code>##     len supp dose
## 1   4.2   VC  0.5
## 2  11.5   VC  0.5
## 3   7.3   VC  0.5
## 11 16.5   VC  1.0
## 12 16.5   VC  1.0
## 13 15.2   VC  1.0
## 14 17.3   VC  1.0
## 15 22.5   VC  1.0
## 21 23.6   VC  2.0
## 22 18.5   VC  2.0
## 23 33.9   VC  2.0
## 24 25.5   VC  2.0
## 31 15.2   OJ  0.5
## 32 21.5   OJ  0.5
## 33 17.6   OJ  0.5
## 34  9.7   OJ  0.5
## 41 19.7   OJ  1.0
## 42 23.3   OJ  1.0
## 43 23.6   OJ  1.0
## 44 26.4   OJ  1.0
## 51 25.5   OJ  2.0
## 52 26.4   OJ  2.0
## 53 22.4   OJ  2.0
## 54 24.5   OJ  2.0</code></pre>
<pre class="r"><code># plot of variable &amp;#39;len&amp;#39; by xName &amp;#39;dose&amp;#39;. The plot is colored by the groupName &amp;#39;supp&amp;#39;
# position = interval between dot plot of the same group
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
      groupName=&amp;#39;supp&amp;#39;, 
      position=position_jitter(0.2), 
      backgroundColor="white", 
      groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;)
)  
 
# Change the interval between stripchart of the same group:
  # position = interval between dot plot of the same group
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
      groupName=&amp;#39;supp&amp;#39;, 
      position=position_dodge(0.8), 
      backgroundColor="white", groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;))

# Change the interval between stripchart of the same group
#position=position_dodge(0.8), add box plot
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
      groupName=&amp;#39;supp&amp;#39;, 
      position=position_dodge(0.8), 
      backgroundColor="white", groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;),
      addBoxplot=TRUE, boxplotFill="white")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-multiple-groups1.png" title="Stripchart with multiple groups" alt="Stripchart with multiple groups" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-multiple-groups2.png" title="Stripchart with multiple groups" alt="Stripchart with multiple groups" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-multiple-groups3.png" title="Stripchart with multiple groups" alt="Stripchart with multiple groups" width="240" /></p>
</div>
<div id="facet-split-a-plot-into-a-matrix-of-pannels" class="section level1">
<h1>Facet : split a plot into a matrix of pannels</h1>
<p>The facet approach splits a plot into a matrix of panels. Each panel shows a different subset of the data.</p>
<div id="facet-with-one-variable" class="section level2">
<h2>Facet with one variable</h2>
<pre class="r"><code>#Facet according to the supp variable
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
            groupName=&amp;#39;supp&amp;#39;,
            legendPosition="top",
            faceting=TRUE, facetingVarNames="supp") 

# Change the direction. possible values are "vertical", "horizontal".
# default is vertical.
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
            groupName=&amp;#39;supp&amp;#39;,
            legendPosition="top",
            faceting=TRUE, facetingVarNames="supp", 
            facetingDirection="horizontal") </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-facet-with-one-variable1.png" title="ggplot2 stripchart and facet approch, one variable" alt="ggplot2 stripchart and facet approch, one variable" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-facet-with-one-variable2.png" title="ggplot2 stripchart and facet approch, one variable" alt="ggplot2 stripchart and facet approch, one variable" width="240" /></p>
</div>
<div id="facet-with-two-variables" class="section level2">
<h2>Facet with two variables</h2>
<pre class="r"><code># Facet by two variables: dose and supp.
# Rows are dose and columns are supp
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
            groupName=&amp;#39;supp&amp;#39;, 
            legendPosition="top",
            faceting=TRUE, facetingVarNames=c("dose","supp"))

# Facet by two variables: reverse the order of the 2 variables
# Rows are supp and columns are dose
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
            groupName=&amp;#39;supp&amp;#39;,
            legendPosition="top",
            faceting=TRUE, facetingVarNames=c("supp", "dose"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-facet-with-two-variables1.png" title="ggplot2 stripchart and facet approch, two variables" alt="ggplot2 stripchart and facet approch, two variables" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-facet-with-two-variables2.png" title="ggplot2 stripchart and facet approch, two variables" alt="ggplot2 stripchart and facet approch, two variables" width="240" /></p>
</div>
<div id="facet-scales" class="section level2">
<h2>Facet scales</h2>
<p>By default, all the panels have the same scale (<code>facetingScales="fixed"</code>). They can be made independent, by setting scales to <code>free</code>, <code>free_x</code>, or <code>free_y</code>.</p>
<pre class="r"><code># Facet with free scales
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
            groupName=&amp;#39;supp&amp;#39;,
            legendPosition="top",
            faceting=TRUE, facetingVarNames=c("dose", "supp"), 
            facetingScales="free")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-facet-free-scale.png" title="ggplot2 stripchart and facet approch, free scale" alt="ggplot2 stripchart and facet approch, free scale" width="288" /></p>
<p><span class="success">As you can see in the above plot, y axis have different scales in the different panels.</span></p>
</div>
<div id="facet-label-apperance" class="section level2">
<h2>Facet label apperance</h2>
<pre class="r"><code># Change facet text font. Possible values for the font style:
  #&amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
            groupName=&amp;#39;supp&amp;#39;,
            legendPosition="top",
            faceting=TRUE, facetingVarNames=c("dose","supp"),
            facetingFont=c(12, &amp;#39;bold.italic&amp;#39;, "red"))

# Change the apperance of the rectangle around facet label
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
            groupName=&amp;#39;supp&amp;#39;,
            legendPosition="top",
            faceting=TRUE, facetingVarNames=c("dose","supp"),
            facetingRect=list(background="white", lineType="solid",
                              lineColor="black", lineSize=1.5)
            )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-facet-label-apperance1.png" title="ggplot2 stripchart and facet approch, facet label" alt="ggplot2 stripchart and facet approch, facet label" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-stripchart-facet-label-apperance2.png" title="ggplot2 stripchart and facet approch, facet label" alt="ggplot2 stripchart and facet approch, facet label" width="240" /></p>
</div>
</div>
<div id="ggplot2.stripchart-function" class="section level1">
<h1>ggplot2.stripchart function</h1>
<div id="description" class="section level2">
<h2>Description</h2>
<p>Plot easily a stripchart plot using <strong>easyGgplot2</strong> R package.</p>
</div>
<div id="usage" class="section level2">
<h2>usage</h2>
<pre class="r"><code>ggplot2.stripchart(data, xName=NULL, yName=NULL, groupName=NULL,
        position=position_jitter(0.2),
        addMean=FALSE, meanPointShape=5, meanPointSize=4,
        meanPointColor="black", meanPointFill="blue",
        addBoxplot=FALSE, boxplotFill="white", 
        boxplotColor="black", boxplotLineWeight=0.5,
        groupColors=NULL, brewerPalette=NULL,...)</code></pre>
</div>
<div id="arguments" class="section level2">
<h2>Arguments</h2>
<table>
<thead>
<tr class="header">
<th align="left">Arguments</th>
<th align="left">Descriptions</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>data</strong></td>
<td align="left">data.frame or a numeric vector. Columns are variables and rows are observations.</td>
</tr>
<tr class="even">
<td align="left"><strong>xName</strong></td>
<td align="left">The name of column containing x variable (i.e groups). Default value is NULL.</td>
</tr>
<tr class="odd">
<td align="left"><strong>yName</strong></td>
<td align="left">The name of column containing y variable. If yName=NULL, data should be a numeric vector.</td>
</tr>
<tr class="even">
<td align="left"><strong>groupName</strong></td>
<td align="left">The name of column containing group variable. This variable is used to color plot according to the group.</td>
</tr>
<tr class="odd">
<td align="left"><strong>position</strong></td>
<td align="left">The position adjustment to use for overlapping points. <strong>Default value is position_jitter(0.2)</strong>.</td>
</tr>
<tr class="even">
<td align="left"><strong>addMean</strong></td>
<td align="left">if TRUE, the mean point is added on the plot for each group. Default value is FALSE.</td>
</tr>
<tr class="odd">
<td align="left"><strong>meanPointShape, meanPointSize</strong></td>
<td align="left">The shape and size of mean point.</td>
</tr>
<tr class="even">
<td align="left"><strong>meanPointColor</strong></td>
<td align="left">border color of the mean point. Default value is “black”.</td>
</tr>
<tr class="odd">
<td align="left"><strong>meanPointFill</strong></td>
<td align="left">Fill color of mean point. This parameter is used only when meanPointShape=21 to 25. Default value is “blue”</td>
</tr>
<tr class="even">
<td align="left"><strong>addBoxplot</strong></td>
<td align="left">if TRUE, box plot is added on the stripchart. Default value is FALSE.</td>
</tr>
<tr class="odd">
<td align="left"><strong>boxplotFill</strong></td>
<td align="left">Fill color of the box plot. <b>Default value is white</b>.</td>
</tr>
<tr class="even">
<td align="left"><strong>dotPosition</strong></td>
<td align="left">Possible values are “center” and “jitter”. Default value is “center”.</td>
</tr>
<tr class="odd">
<td align="left"><strong>boxplotColor</strong></td>
<td align="left">Box plot line color. <b>Default value is black.</b></td>
</tr>
<tr class="even">
<td align="left"><strong>boxplotLineWeight</strong></td>
<td align="left">Box plot line weight. <b>Default value is 0.5.</b></td>
</tr>
<tr class="odd">
<td align="left"><strong>groupColors</strong></td>
<td align="left">Color of groups. groupColors should have the same length as groups.</td>
</tr>
<tr class="even">
<td align="left"><strong>brewerPalette</strong></td>
<td align="left">This can be also used to indicate group colors. In this case the parameter groupColors should be NULL. e.g: brewerPalette=“Paired”.</td>
</tr>
<tr class="odd">
<td align="left"><strong>….</strong></td>
<td align="left">Other arguments passed on to ggplot2.customize custom function or to geom_jitter and to geom_boxplot functions from ggplot2 package.</td>
</tr>
</tbody>
</table>
<p><span class="warning">The other arguments which can be used are described at this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2 customize</a>. They are used to customize the plot (axis, title, background, color, legend, ….) generated <strong>using ggplot2</strong> or <strong>easyGgplot2</strong> R package.</span></p>
</div>
<div id="examples" class="section level2">
<h2>Examples</h2>
<pre class="r"><code>df <- ToothGrowth
ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
        mainTitle="Plot of length according\n to the dose",
        xtitle="Dose (mg)", ytitle="Length")

#Or use this
plot<-ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;)
plot<-ggplot2.customize(plot,
        mainTitle="Plot of length according\n to the dose",
        xtitle="Dose (mg)", ytitle="Length")
print(plot)</code></pre>
<p><span class="success"> ggplot2.jitter can be also used instead of ggplot2.stripchart.</span></p>
<p><br/></p>
</div>
</div>
<div id="easy-ggplot2-ebook" class="section level1">
<h1>Easy ggplot2 ebook</h1>
<p><span class="success">Note that an eBook is available on <strong>easyGgplot2</strong> package <a href="https://www.sthda.com/english/english/download/download-4+easy-ggplot2-book.php">here</a>.</span></p>
<div class="block">
<p>By Alboukadel Kassambara</p>
<p>Copyright 2014 Alboukadel Kassambara. All rights reserved.</p>
<p>Published by STHDA (<a href="https://www.sthda.com/english">https://www.sthda.com/english</a>).</p>
<p>September 2014 : First edition.</p>
<p><strong>Licence</strong> : This document is under creative commons licence (<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">http://creativecommons.org/licenses/by-nc-sa/3.0/</a>).</p>
<p><strong>Contact</strong> : Alboukadel Kassambara <a href="mailto:alboukadel.kassambara@gmail.com">alboukadel.kassambara@gmail.com</a></p>
</div>
<p><br/></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning">This analysis was performed using R (ver. 3.1.0), easyGgplot2 (ver 1.0.0) and ggplot2 (ver 1.0.0).</span></p>
<ul>
<li><a href="http://docs.ggplot2.org/current/">ggplot2 online documentation</a></li>
<li><a href="http://www.cookbook-r.com/Graphs/">Cookbook for R</a></li>
</ul>
</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 Feb 2015 21:14:17 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[ggplot2 boxplot :  Easy box and whisker plots maker function]]></title>
			<link>https://www.sthda.com/english/wiki/ggplot2-boxplot-easy-box-and-whisker-plots-maker-function</link>
			<guid>https://www.sthda.com/english/wiki/ggplot2-boxplot-easy-box-and-whisker-plots-maker-function</guid>
			<description><![CDATA[<!-- START HTML -->

            
  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#install-and-load-easyggplot2-package">Install and load easyGgplot2 package</a></li>
<li><a href="#data-format">Data format</a></li>
<li><a href="#basic-box-plot">Basic box plot</a></li>
<li><a href="#box-plot-with-mean-point-and-dots">Box plot with mean point and dots</a></li>
<li><a href="#change-the-box-plot-line-type-and-point-shape">Change the box plot line type and point shape</a></li>
<li><a href="#customize-your-box-plot">Customize your box plot</a><ul>
<li><a href="#parameters">Parameters</a></li>
<li><a href="#main-title-and-axis-labels">Main title and axis labels</a></li>
<li><a href="#axis-ticks">Axis ticks</a></li>
<li><a href="#background-and-colors">Background and colors</a><ul>
<li><a href="#change-box-plot-background-and-fill-colors">Change box plot background and fill colors</a></li>
<li><a href="#change-box-plot-color-according-to-the-group">Change box plot color according to the group</a></li>
</ul></li>
<li><a href="#legend">Legend</a><ul>
<li><a href="#legend-position">Legend position</a></li>
<li><a href="#legend-background-color-title-and-text-font-styles">Legend background color, title and text font styles</a></li>
<li><a href="#change-the-order-of-items-in-the-legend-remove-plot-legend">Change the order of items in the legend, remove plot legend</a></li>
</ul></li>
<li><a href="#axis-scales">Axis scales</a></li>
<li><a href="#create-a-customized-plots-with-few-r-code">Create a customized plots with few R code</a></li>
</ul></li>
<li><a href="#box-plot-with-multiple-groups">Box plot with multiple groups</a></li>
<li><a href="#facet-split-a-plot-into-a-matrix-of-panels">Facet : split a plot into a matrix of panels</a><ul>
<li><a href="#facet-with-one-variable">Facet with one variable</a></li>
<li><a href="#facet-with-two-variables">Facet with two variables</a></li>
<li><a href="#facet-scales">Facet scales</a></li>
<li><a href="#facet-label-apperance">Facet label apperance</a></li>
</ul></li>
<li><a href="#ggplot2.boxplot-function">ggplot2.boxplot function</a><ul>
<li><a href="#description">Description</a></li>
<li><a href="#usage">usage</a></li>
<li><a href="#arguments">Arguments</a></li>
<li><a href="#examples">Examples</a></li>
</ul></li>
<li><a href="#easy-ggplot2-ebook">Easy ggplot2 ebook</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<hr />
<div id="introduction" class="section level1">
<h1>Introduction</h1>
<p><strong>ggplot2.boxplot</strong> is a function, to plot easily a <strong>box plot</strong> (also known as a <strong>box and whisker plot</strong>) with <strong>R statistical software</strong> <strong>using ggplot2</strong> package. It can also be used to <strong>customize</strong> quickly the plot parameters including <strong>main title</strong>, <strong>axis labels</strong>, <strong>legend</strong>, <strong>background</strong> and <strong>colors</strong>. ggplot2.boxplot function is from <strong>easyGgplot2</strong> R package. An R script is available in the next section to install the package.</p>
<p>The aim of this <strong>ggplot2 tutorial</strong> is to show you step by step, how to make and customize a <strong>box plot</strong> using <strong>ggplot2.boxplot</strong> function.</p>
<p>At the end of this article you will be able to draw, with few R code, the following plot:</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-demo.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="336" /></p>

<p><span class="warning"><strong>ggplot2.boxplot</strong> function is described in detail at the end of this document.</span></p>
</div>
<div id="install-and-load-easyggplot2-package" class="section level1">
<h1>Install and load easyGgplot2 package</h1>
<p><strong>easyGgplot2</strong> R package can be installed as follow :</p>
<pre class="r"><code>install.packages("devtools")
library(devtools)
install_github("easyGgplot2", "kassambara")</code></pre>
<p>Load the package using this R code :</p>
<pre class="r"><code>library(easyGgplot2)</code></pre>
</div>
<div id="data-format" class="section level1">
<h1>Data format</h1>
<p><span class="success">The data must be a numeric vector or a data.frame (columns are variables and rows are observations).</span></p>
<p>ToothGrowth data is used in the following examples.</p>
<pre class="r"><code># create a numeric vector
numVector<-rnorm(100)
head(numVector)</code></pre>
<pre><code>## [1] -1.1381  0.5408 -0.9359  0.4949 -1.1467 -0.1464</code></pre>
<pre class="r"><code># data.frame
df <- ToothGrowth
head(df)</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>
<br/>

<div class="block">
<p>ToothGrowth describes the effect of Vitamin C on Tooth growth in Guinea pigs. The response is the length (len) of teeth in each of 10 guinea pigs at each of three dose levels of Vitamin C (0.5, 1, and 2 mg) with each of two delivery methods (orange juice or ascorbic acid).</p>
The data is a data frame with 60 observations on 3 variables.
* [,1] len numeric Tooth length.
* [,2] supp factor Supplement type (VC or OJ).
* [,3] dose numeric Dose in milligrams.

</div>
<p><br/></p>
</div>
<div id="basic-box-plot" class="section level1">
<h1>Basic box plot</h1>
<pre class="r"><code># Box plot from a single numeric vector 
ggplot2.boxplot(data=numVector)

# Basic box plot from the vector "len"
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;)

# Change the orientation: Horizontal box plot
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                orientation="horizontal")

# Notched box plot
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                notch=TRUE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-basic-box-plot1.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-basic-box-plot2.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-basic-box-plot3.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-basic-box-plot4.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /></p>
<p><span class="warning"> <strong>notch</strong>: If TRUE, make a notched box plot. The notch displays a confidence interval around the median which is normally based on the median +/- 1.57 x IQR/sqrt of n. Notches are used to compare groups; if the notches of two boxes do not overlap, this is strong evidence that the medians differ. </span></p>
</div>
<div id="box-plot-with-mean-point-and-dots" class="section level1">
<h1>Box plot with mean point and dots</h1>
<p>Each dot represents one observation and the mean point corresponds to the mean value of the observations in a given group.</p>
<pre class="r"><code># Box plot with mean point
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                addMean=TRUE, meanPointShape=23, meanPointSize=2.5,
                meanPointColor="black", meanPointFill="blue")

# Box plot with centered dots
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                addDot=TRUE, dotSize=1, dotPosition="center")

# Box plot with jittered dots. jitter: degree of jitter in x direction
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                addDot=TRUE, dotSize=1.7, dotPosition="jitter",
                jitter=0.2)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-boxplot-with-dots1.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-boxplot-with-dots2.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-boxplot-with-dots3.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /></p>
</div>
<div id="change-the-box-plot-line-type-and-point-shape" class="section level1">
<h1>Change the box plot line type and point shape</h1>
<p><span class="warning">Different <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">point shapes</a> and <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">line types</a> can be used in the plot. By default, ggplot2 uses solid line type and circle shape.</span></p>
<ul>
<li>The different <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">point shapes</a> in R are described <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">here</a>.</li>
<li>The available <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">line types</a> are shown <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">here</a>.</li>
</ul>
<pre class="r"><code># Change the box plot line color and line type
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                colour="red", linetype="dotted")

# Change outlier color, shape and size
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                outlier.colour="red", outlier.shape=8,
                outlier.size=4)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-line-type-and-point-shape1.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-line-type-and-point-shape2.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /></p>
</div>
<div id="customize-your-box-plot" class="section level1">
<h1>Customize your box plot</h1>
<div id="parameters" class="section level2">
<h2>Parameters</h2>
<p>The arguments that can be used to customize x and y axis are listed below :</p>
<table>
<thead>
<tr class="header">
<th align="left">Parameters</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>mainTitle</strong></td>
<td align="left">the title of the plot</td>
</tr>
<tr class="even">
<td align="left"><strong>mainTitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style (“italic”, “bold”, “bold.italic”) and the color of x and y axis titles. Default value is: mainTitleFont=c(14, “bold”, “black”).</td>
</tr>
<tr class="odd">
<td align="left"><strong>xShowTitle, yShowTitle</strong></td>
<td align="left">if TRUE, x and y axis titles will be shown. Set the value to FALSE to hide axis labels. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtitle, ytitle</strong></td>
<td align="left">x and y axis labels. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xtitleFont, ytitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis titles. Possible values for the <strong>style</strong>:“plain”, “italic”, “bold”, “bold.italic”. Color can be specified as an hexadecimal code (e.g: “#FFCC00”) or by the name (e.g : “red”, “green”). Default values are <code>xtitleFont=c(14,"bold", "black"), ytitleFont=c(14,"bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xlim, ylim</strong></td>
<td align="left">limit for the x and y axis. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xScale, yScale</strong></td>
<td align="left">x and y axis scales. Possible values : c(“none”, “log2”, “log10”). e.g: yScale=“log2”. Default values are <code>NULL</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xShowTickLabel, yShowTickLabel</strong></td>
<td align="left">if TRUE, x and y axis tick mark labels will be shown. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xTickLabelFont, yTickLabelFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis tick label fonts. Default value are <code>xTickLabelFont=c(12, "bold", "black"), yTickLabelFont=c(12, "bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtickLabelRotation, ytickLabelRotation</strong></td>
<td align="left">Rotation angle of x and y axis tick labels. Default value are <code>0</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>hideAxisTicks</strong></td>
<td align="left">if TRUE, x and y axis ticks are hidden. Default value is <code>FALSE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>axisLine</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the line type and the color of axis lines. Default value is <code>c(0.5, "solid", "#E5E5E5")</code>.</td>
</tr>
</tbody>
</table>
<p>For more details follow this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2.customize</a>.</p>
</div>
<div id="main-title-and-axis-labels" class="section level2">
<h2>Main title and axis labels</h2>
<pre class="r"><code># Change main title and axis titles
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                mainTitle="Plot of length \n by dose",
                xtitle="Dose (mg)", ytitle="Length")

# Customize title styles. Possible values for the font style :
  # &amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
              xtitle="Dose (mg)", ytitle="Length",
              mainTitle="Plot of length \n by dose",
              mainTitleFont=c(14,"bold.italic", "red"),
              xtitleFont=c(14,"bold", "#993333"), 
              ytitleFont=c(14,"bold", "#993333"))

# Hide x an y axis titles
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                xShowTitle=FALSE, yShowTitle=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-title1.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-title2.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-title3.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /></p>
</div>
<div id="axis-ticks" class="section level2">
<h2>Axis ticks</h2>
<pre class="r"><code># Axis ticks labels and orientaion
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                xTickLabelFont=c(14,"bold", "#993333"),
                yTickLabelFont=c(14,"bold", "#993333"),
                xtickLabelRotation=45, ytickLabelRotation=45)

# Hide axis tick labels
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                xShowTickLabel=FALSE, yShowTickLabel=FALSE)

# Hide axis ticks
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                xShowTickLabel=FALSE, yShowTickLabel=FALSE,
                hideAxisTicks=TRUE)

# AxisLine : a vector of length 3 indicating the size,
  #the line type and the color of axis lines
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                axisLine=c(1, "solid", "darkblue"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-axis-ticks1.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-axis-ticks2.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-axis-ticks3.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-axis-ticks4.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /></p>
</div>
<div id="background-and-colors" class="section level2">
<h2>Background and colors</h2>
<div id="change-box-plot-background-and-fill-colors" class="section level3">
<h3>Change box plot background and fill colors</h3>
<pre class="r"><code># change background color to "white". Default is "gray"
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="white")

# change background color to "lightblue" and grid color to "white"
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="lightblue", gridColor="white")

# change plot fill color
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="white", fill=&amp;#39;#FFAAD4&amp;#39;)

# remove grid; remove top and right borders around the plot;
# change  axis lines
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                backgroundColor="white", fill=&amp;#39;#FFAAD4&amp;#39;,
                removePanelGrid=TRUE,removePanelBorder=TRUE,
                axisLine=c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-background-color1.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-background-color2.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-background-color3.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-background-color4.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="163.2" /></p>
</div>
<div id="change-box-plot-color-according-to-the-group" class="section level3">
<h3>Change box plot color according to the group</h3>
<p><span class="warning">Colors can be specified as a hexadecimal RGB triplet, such as <code>"#FFCC00"</code> or by names (e.g : <code>"red"</code> ). You can also use other color scales, such as ones taken from the RColorBrewer package. The different <a href="https://www.sthda.com/english/english/wiki/colors-in-r">color systems</a> available in R have been described in detail <a href="https://www.sthda.com/english/english/wiki/colors-in-r">here</a>.<span></p>
<p><span class="success">To change <strong>box plot</strong> color according to the group, you have to specify the name of the data column containing the groups using the argument <code>groupName</code>. Use the argument <code>groupColors</code>, to specify colors by <code>hexadecimal</code> code or by <code>name</code>. In this case, the length of groupColors should be the same as the number of the groups. Use the argument <code>brewerPalette</code>, to specify colors using <code>RColorBrewer</code>palette.</span></p>
<pre class="r"><code># color the box plot accoording to the groupName "dose"
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;)

# change group colors using hexadecimal colors
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;))

# change group colors using brewer palette: "Paired"
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                brewerPalette="Paired")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-box-plot-color1.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-box-plot-color2.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-box-plot-color3.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="240" /></p>
<br/>
<div class="block">
<p>Color can also be changed by using names as follow :</p>
<pre class="r"><code># change group colors using color names
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                groupName=&amp;#39;dose&amp;#39;,
                groupColors=c(&amp;#39;blue&amp;#39;,&amp;#39;red&amp;#39;,&amp;#39;green&amp;#39;))</code></pre>
</div>
</div>
</div>
<div id="legend" class="section level2">
<h2>Legend</h2>
<div id="legend-position" class="section level3">
<h3>Legend position</h3>
<pre class="r"><code># Change the legend position to "top" 
  # (possible values: "left","top", "right", "bottom")
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                legendPosition="top")

# legendPosition can be also a numeric vector c(x, y)
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                legendPosition=c(0.8,0.2))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-legend-position1.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-legend-position2.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="240" /></p>
<p><span class="warning">It is also possible to position the legend inside the plotting area. You have to indicate the x, y coordinates of legend box. x and y values must be between 0 and 1. <code>c(0,0)</code> corresponds to <code>"bottom left"</code> and <code>c(1,1)</code> corresponds to <code>"top right"</code> position.</span></p>
</div>
<div id="legend-background-color-title-and-text-font-styles" class="section level3">
<h3>Legend background color, title and text font styles</h3>
<pre class="r"><code># Change legend background color, title and text font styles
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
        # legendTitleFont=c(size, style, color)
        legendTitle="Dose (mg)",
        legendTitleFont=c(10, "bold", "blue"),
        #legendTextFont=c(size, style, color)
        legendTextFont=c(10, "bold.italic", "red"),
        # legendBackground: c(fill, lineSize, lineType, lineColor)
        legendBackground=c("lightblue", 0.5, "solid", "darkblue" )
        )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-legend-background-and-title.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="288" /></p>
</div>
<div id="change-the-order-of-items-in-the-legend-remove-plot-legend" class="section level3">
<h3>Change the order of items in the legend, remove plot legend</h3>
<pre class="r"><code># Change the order of items in the legend
 # legendItemOrder : character vector indicating 
# the order of items in the legends.
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                legendItemOrder=c("2", "1", "0.5"))
    
# Remove plot legend
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                showLegend=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-legend-item-order1.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-legend-item-order2.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="240" /></p>
</div>
</div>
<div id="axis-scales" class="section level2">
<h2>Axis scales</h2>
<p>Possible values for y axis scale are “none”, “log2” and log10. Default value is “none”.</p>
<pre class="r"><code># Change y axis limit
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                ylim=c(0,50))

# y Log scale. Possible values="none", "log2" and "log10"
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
                yScale="log2")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-axis-scale1.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-axis-scale2.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="240" /></p>
</div>
<div id="create-a-customized-plots-with-few-r-code" class="section level2">
<h2>Create a customized plots with few R code</h2>
<pre class="r"><code># Customized boxplot with centered dot plot
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
        groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;), showLegend=FALSE,
        backgroundColor="white", xtitle="Dose (mg)", 
        ytitle="length", mainTitle="Plot of length \n by dose",
        addDot=TRUE, dotSize=1)

# Remove grid; Remove Top and right border around the plot
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;dose&amp;#39;,
        groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;), showLegend=FALSE,
        backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
        mainTitle="Plot of length \n by dose",
        addDot=TRUE, dotSize=1,
        removePanelGrid=TRUE,removePanelBorder=TRUE,
        axisLine=c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-customized-plot1.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-customized-plot2.png" title="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" alt="r data visualization with ggplot2 boxplot : tutorial on how to use ggplot2.boxplot function to easily make a box plot using ggplot2 in R statistical software" width="240" /></p>
</div>
</div>
<div id="box-plot-with-multiple-groups" class="section level1">
<h1>Box plot with multiple groups</h1>
<p><span class="blue"><strong>The data format is:</strong></span></p>
<pre><code>##     len supp dose
## 1   4.2   VC  0.5
## 2  11.5   VC  0.5
## 3   7.3   VC  0.5
## 11 16.5   VC  1.0
## 12 16.5   VC  1.0
## 13 15.2   VC  1.0
## 14 17.3   VC  1.0
## 15 22.5   VC  1.0
## 21 23.6   VC  2.0
## 22 18.5   VC  2.0
## 23 33.9   VC  2.0
## 24 25.5   VC  2.0
## 31 15.2   OJ  0.5
## 32 21.5   OJ  0.5
## 33 17.6   OJ  0.5
## 34  9.7   OJ  0.5
## 41 19.7   OJ  1.0
## 42 23.3   OJ  1.0
## 43 23.6   OJ  1.0
## 44 26.4   OJ  1.0
## 51 25.5   OJ  2.0
## 52 26.4   OJ  2.0
## 53 22.4   OJ  2.0
## 54 24.5   OJ  2.0</code></pre>
<pre class="r"><code># plot of variable &amp;#39;len&amp;#39; by xName &amp;#39;dose&amp;#39;. The plot is colored by the groupName &amp;#39;supp&amp;#39;
# position = interval between box plot of the same group
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;, 
      position=position_dodge(0.8),
      backgroundColor="white", groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;),
      legendPosition="top")  

# add dots
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;, 
        position=position_dodge(0.8),
        backgroundColor="white", groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;),
        addDot=TRUE, dotSize=1,legendPosition="top") </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-multiple-boxplots1.png" title="Boxplot with multiple groups" alt="Boxplot with multiple groups" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-multiple-boxplots2.png" title="Boxplot with multiple groups" alt="Boxplot with multiple groups" width="240" /></p>
</div>
<div id="facet-split-a-plot-into-a-matrix-of-panels" class="section level1">
<h1>Facet : split a plot into a matrix of panels</h1>
<p>The <strong>facet</strong> approach <strong>splits a plot</strong> into a matrix of panels. Each panel shows a different subset of the data.</p>
<div id="facet-with-one-variable" class="section level2">
<h2>Facet with one variable</h2>
<pre class="r"><code># Facet according to the supp variable
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
        legendPosition="top", 
        faceting=TRUE, facetingVarNames="supp") 

# Change the direction. possible values are "vertical", horizontal".
# default is vertical.
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
        legendPosition="top",
        faceting=TRUE, facetingVarNames="supp",
        facetingDirection="horizontal") </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-facet-with-one-variable1.png" title="ggplot2 boxplot and facet approch, one variable" alt="ggplot2 boxplot and facet approch, one variable" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-facet-with-one-variable2.png" title="ggplot2 boxplot and facet approch, one variable" alt="ggplot2 boxplot and facet approch, one variable" width="240" /></p>
</div>
<div id="facet-with-two-variables" class="section level2">
<h2>Facet with two variables</h2>
<pre class="r"><code># Facet by two variables: dose and supp.
# Rows are dose and columns are supp
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
        legendPosition="top", faceting=TRUE,
        facetingVarNames=c("dose","supp"))

# Facet by two variables: reverse the order of the 2 variables
# Rows are supp and columns are dose
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
        legendPosition="top", faceting=TRUE,
        facetingVarNames=c("supp", "dose"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-facet-with-two-variables1.png" title="ggplot2 boxplot and facet approch, two variables" alt="ggplot2 boxplot and facet approch, two variables" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-facet-with-two-variables2.png" title="ggplot2 boxplot and facet approch, two variables" alt="ggplot2 boxplot and facet approch, two variables" width="240" /></p>
</div>
<div id="facet-scales" class="section level2">
<h2>Facet scales</h2>
<p>By default, all the panels have the same scale (<code>facetingScales="fixed"</code>). They can be made independent, by setting scales to <code>free</code>, <code>free_x</code>, or <code>free_y</code>.</p>
<pre class="r"><code># Facet with free scales
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;, legendPosition="top",
            faceting=TRUE, facetingVarNames=c("dose", "supp"),
            facetingScales="free")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-facet-free-scale.png" title="ggplot2 boxplot and facet approch, free scale" alt="ggplot2 boxplot and facet approch, free scale" width="240" /></p>
<p><span class="success">As you can see in the above plot, y axis have different scales in the different panels.</span></p>
</div>
<div id="facet-label-apperance" class="section level2">
<h2>Facet label apperance</h2>
<pre class="r"><code># Change facet text font. Possible values for the font style:
  #&amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
        legendPosition="top",
        faceting=TRUE, facetingVarNames=c("dose","supp"),
        facetingFont=c(12, &amp;#39;bold.italic&amp;#39;, "red"))

# Change the apperance of the rectangle around facet label
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;, groupName=&amp;#39;supp&amp;#39;,
      legendPosition="top",
      faceting=TRUE, facetingVarNames=c("dose","supp"),
      facetingRect=list(background="white", lineType="solid",
                        lineColor="black", lineSize=1.5)
      )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-facet-label-apperance1.png" title="ggplot2 boxplot and facet approch, facet label" alt="ggplot2 boxplot and facet approch, facet label" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-boxplot-facet-label-apperance2.png" title="ggplot2 boxplot and facet approch, facet label" alt="ggplot2 boxplot and facet approch, facet label" width="240" /></p>
</div>
</div>
<div id="ggplot2.boxplot-function" class="section level1">
<h1>ggplot2.boxplot function</h1>
<div id="description" class="section level2">
<h2>Description</h2>
<p>Plot easily a <strong>boxplot</strong> with R package <strong>easyGgplot2</strong>.</p>
</div>
<div id="usage" class="section level2">
<h2>usage</h2>
<pre class="r"><code>ggplot2.boxplot(data, xName=NULL, yName=NULL, groupName=NULL,
        addMean=FALSE, meanPointShape=23, meanPointSize=4,
        meanPointColor="black", meanPointFill="blue",
        addDot=FALSE, dotSize=1,
        dotPosition=c("center", "jitter"), jitter=0.2,
        groupColors=NULL, brewerPalette=NULL,...)</code></pre>
</div>
<div id="arguments" class="section level2">
<h2>Arguments</h2>
<table>
<thead>
<tr class="header">
<th align="left">Arguments</th>
<th align="left">Descriptions</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>data</strong></td>
<td align="left">data.frame or a numeric vector. Columns are variables and rows are observations.</td>
</tr>
<tr class="even">
<td align="left"><strong>xName</strong></td>
<td align="left">The name of column containing x variable (i.e groups). Default value is NULL.</td>
</tr>
<tr class="odd">
<td align="left"><strong>yName</strong></td>
<td align="left">The name of column containing y variable. If yName=NULL, data should be a numeric vector.</td>
</tr>
<tr class="even">
<td align="left"><strong>groupName</strong></td>
<td align="left">The name of column containing group variable. This variable is used to color plot according to the group.</td>
</tr>
<tr class="odd">
<td align="left"><strong>addMean</strong></td>
<td align="left">if TRUE, the mean point is added on the plot for each group. Default value is FALSE.</td>
</tr>
<tr class="even">
<td align="left"><strong>meanPointShape, meanPointSize</strong></td>
<td align="left">The shape and size of mean point.</td>
</tr>
<tr class="odd">
<td align="left"><strong>meanPointColor</strong></td>
<td align="left">Border color of the mean point. Default value is “black”.</td>
</tr>
<tr class="even">
<td align="left"><strong>meanPointFill</strong></td>
<td align="left">Fill color of mean point. This parameter is used only when meanPointShape=21 to 25. Default value is “blue”</td>
</tr>
<tr class="odd">
<td align="left"><strong>addDot</strong></td>
<td align="left">If TRUE, dotplot is added on the boxplot. Default value is FALSE.</td>
</tr>
<tr class="even">
<td align="left"><strong>dotSize</strong></td>
<td align="left">The size of dots.</td>
</tr>
<tr class="odd">
<td align="left"><strong>dotPosition</strong></td>
<td align="left">Possible values are “center” and “jitter”. Default value is “center”.</td>
</tr>
<tr class="even">
<td align="left"><strong>jitter</strong></td>
<td align="left">Degree of jitter in x direction. Default value is 0.2.</td>
</tr>
<tr class="odd">
<td align="left"><strong>groupColors</strong></td>
<td align="left">Color of groups. groupColors should have the same length as groups.</td>
</tr>
<tr class="even">
<td align="left"><strong>brewerPalette</strong></td>
<td align="left">This can be also used to indicate group colors. In this case the parameter groupColors should be NULL. e.g: brewerPalette=“Paired”.</td>
</tr>
<tr class="odd">
<td align="left"><strong>….</strong></td>
<td align="left">Other arguments passed on to <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2.customize</a> function or to geom_dotplot and to geom_boxplot functions from ggplot2 package.</td>
</tr>
</tbody>
</table>
<p><span class="warning">The other arguments which can be used are described at this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2 customize</a>. They are used to customize the plot (axis, title, background, color, legend, ….) generated <strong>using ggplot2</strong> or <strong>easyGgplot2</strong> R package.</span></p>
</div>
<div id="examples" class="section level2">
<h2>Examples</h2>
<pre class="r"><code>library(easyGgplot2)
df <- ToothGrowth
ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                mainTitle="Plot of length according\n to the dose",
                xtitle="Dose (mg)", ytitle="Length")

#Or use this
plot<-ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;)
plot<-ggplot2.customize(plot, mainTitle="Plot of length according\n to the dose",
                        xtitle="Dose (mg)", ytitle="Length")
print(plot)</code></pre>
<p><br/></p>
</div>
</div>
<div id="easy-ggplot2-ebook" class="section level1">
<h1>Easy ggplot2 ebook</h1>
<p><span class="success">Note that an eBook is available on <strong>easyGgplot2</strong> package <a href="https://www.sthda.com/english/english/download/download-4+easy-ggplot2-book.php">here</a>.</span></p>
<div class="block">
<p>By Alboukadel Kassambara</p>
<p>Copyright 2014 Alboukadel Kassambara. All rights reserved.</p>
<p>Published by STHDA (<a href="https://www.sthda.com/english">https://www.sthda.com/english</a>).</p>
<p>September 2014 : First edition.</p>
<p><strong>Licence</strong> : This document is under creative commons licence (<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">http://creativecommons.org/licenses/by-nc-sa/3.0/</a>).</p>
<p><strong>Contact</strong> : Alboukadel Kassambara <a href="mailto:alboukadel.kassambara@gmail.com">alboukadel.kassambara@gmail.com</a></p>
</div>
<p><br/></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning">This analysis was performed using R (ver. 3.1.0), easyGgplot2 (ver 1.0.0) and ggplot2 (ver 1.0.0).</span></p>
<ul>
<li><a href="http://docs.ggplot2.org/current/">ggplot2 online documentation</a></li>
<li><a href="http://www.cookbook-r.com/Graphs/">Cookbook for R</a></li>
</ul>
</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 Feb 2015 21:11:34 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[ggplot2.scatterplot : Easy scatter plot using ggplot2 and R statistical software]]></title>
			<link>https://www.sthda.com/english/wiki/ggplot2-scatterplot-easy-scatter-plot-using-ggplot2-and-r-statistical-software</link>
			<guid>https://www.sthda.com/english/wiki/ggplot2-scatterplot-easy-scatter-plot-using-ggplot2-and-r-statistical-software</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#install-and-load-easyggplot2-package">Install and load easyGgplot2 package</a></li>
<li><a href="#data-format">Data format</a></li>
<li><a href="#basic-scatter-plot-plot">Basic scatter plot plot</a><ul>
<li><a href="#scatterplot-with-regression-line">Scatterplot with regression line</a></li>
</ul></li>
<li><a href="#change-the-line-type-and-the-point-shapes-of-the-scatter-plot">Change the line type and the point shapes of the scatter plot</a></li>
<li><a href="#scatter-plot-plot-with-multiple-groups">Scatter plot plot with multiple groups</a></li>
<li><a href="#customize-your-scatter-plot">Customize your scatter plot</a><ul>
<li><a href="#parameters">Parameters</a></li>
<li><a href="#main-title-and-axis-labels">Main title and axis labels</a></li>
<li><a href="#axis-ticks">Axis ticks</a></li>
<li><a href="#background-and-colors">Background and colors</a><ul>
<li><a href="#change-scatter-plot-plot-background-and-point-colors">Change scatter plot plot background and point colors</a></li>
<li><a href="#change-scatter-plot-color-according-to-the-group">Change scatter plot color according to the group</a></li>
</ul></li>
<li><a href="#legend">Legend</a><ul>
<li><a href="#legend-position">Legend position</a></li>
<li><a href="#legend-background-color-title-and-text-font-styles">Legend background color, title and text font styles</a></li>
</ul></li>
<li><a href="#axis-scales">Axis scales</a></li>
<li><a href="#create-a-customized-plots-with-few-r-code">Create a customized plots with few R code</a></li>
</ul></li>
<li><a href="#faceting-split-a-plot-into-a-matrix-of-pannels">Faceting : split a plot into a matrix of pannels</a><ul>
<li><a href="#facet-with-one-variable">Facet with one variable</a></li>
<li><a href="#facet-with-two-variables">Facet with two variables</a></li>
<li><a href="#facet-scales">Facet scales</a></li>
<li><a href="#facet-label-apperance">Facet label apperance</a></li>
</ul></li>
<li><a href="#ggplot2.scatterplot-function">ggplot2.scatterplot function</a><ul>
<li><a href="#description">Description</a></li>
<li><a href="#usage">usage</a></li>
<li><a href="#arguments">Arguments</a></li>
<li><a href="#examples">Examples</a></li>
</ul></li>
<li><a href="#easy-ggplot2-ebook">Easy ggplot2 ebook</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<div id="introduction" class="section level1">
<h1>Introduction</h1>
<p><strong>ggplot2.scatterplot</strong> is an easy to use function to make and customize quickly a <strong>scatter plot</strong> using <strong>R software</strong> and <strong>ggplot2</strong> package. <strong>ggplot2.scatterplot</strong> function is from <a href="https://www.sthda.com/english/english/wiki/easyggplot2"><strong>easyGgplot2</strong></a> R package. An R script is available in the next section to install the package.</p>
<p>The aim of this <strong>tutorial</strong> is to show you step by step, how to plot and customize a <strong>scatter plot</strong> using ggplot2.scatterplot function.</p>
<p>At the end of this tutorial you will be able to draw, with few R code, the following plots:</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-demo1.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-demo2.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /></p>

<p><span class="warning"><strong>ggplot2.scatterplot</strong> function is described in detail at the end of this document.</span></p>
</div>
<div id="install-and-load-easyggplot2-package" class="section level1">
<h1>Install and load easyGgplot2 package</h1>
<p><strong>easyGgplot2</strong> R package can be installed as follow :</p>
<pre class="r"><code>install.packages("devtools")
library(devtools)
install_github("easyGgplot2", "kassambara")</code></pre>
<p>Load the package using this R code :</p>
<pre class="r"><code>library(easyGgplot2)</code></pre>
</div>
<div id="data-format" class="section level1">
<h1>Data format</h1>
<p><span class="blue">The data must be a data.frame (columns are variables and rows are observations).</span></p>
<p><code>mtcars</code> data is used in the following examples.</p>
<pre class="r"><code>df <- mtcars[, c("mpg", "cyl", "wt", "qsec", "vs")]
head(df)</code></pre>
<pre><code>##                    mpg cyl    wt  qsec vs
## Mazda RX4         21.0   6 2.620 16.46  0
## Mazda RX4 Wag     21.0   6 2.875 17.02  0
## Datsun 710        22.8   4 2.320 18.61  1
## Hornet 4 Drive    21.4   6 3.215 19.44  1
## Hornet Sportabout 18.7   8 3.440 17.02  0
## Valiant           18.1   6 3.460 20.22  1</code></pre>
<br/>

<div class="block">
<p><span class="blue">mtcars : Motor Trend Car Road Tests.</span></p>
<p><strong>Description</strong>: The data comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973 - 74 models).</p>
<p><strong>Format</strong>: A data frame with 32 observations on 4 variables.</p>
<ul>
<li>[, 1] mpg Miles/(US) gallon</li>
<li>[, 2] cyl Number of cylinders</li>
<li>[, 3] wt Weight (lb/1000)</li>
<li>[, 4] qsec 1/4 mile time</li>
<li>[, 5] vs V/S</li>
</ul>
</div>
<p><br/></p>
</div>
<div id="basic-scatter-plot-plot" class="section level1">
<h1>Basic scatter plot plot</h1>
<pre class="r"><code># Basic scatter plot of mpg according to cyl
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;)

# Change point size
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, size=3)

# change point size according to a numeric variable (qsec)
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
                    mapping=aes(size = qsec))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-basic-scatter-plot1.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-basic-scatter-plot2.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-basic-scatter-plot3.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /></p>
<div id="scatterplot-with-regression-line" class="section level2">
<h2>Scatterplot with regression line</h2>
<pre class="r"><code>#Add linear regression line
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, 
                    addRegLine=TRUE, regLineColor="blue")
                    
#Add the 95% confidence region
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
            addRegLine=TRUE, regLineColor="blue",
            addConfidenceInterval=TRUE)
                    
#Use loess (local fiting as smooth method)
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
            addRegLine=TRUE, regLineColor="blue",
            addConfidenceInterval=TRUE, smoothingMethod="loess")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-scatterplot_with_regression_line1.png" title="ggplot2 scatterplot" alt="ggplot2 scatterplot" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-scatterplot_with_regression_line2.png" title="ggplot2 scatterplot" alt="ggplot2 scatterplot" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-scatterplot_with_regression_line3.png" title="ggplot2 scatterplot" alt="ggplot2 scatterplot" width="240" /></p>
</div>
</div>
<div id="change-the-line-type-and-the-point-shapes-of-the-scatter-plot" class="section level1">
<h1>Change the line type and the point shapes of the scatter plot</h1>
<p><span class="warning">Different <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">point shapes</a> and <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">line types</a> can be used in the plot. By default, ggplot2 uses solid line type and circle shape.</span></p>
<ul>
<li>The different <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">point shapes</a> in R are described <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">here</a>.</li>
<li>The available <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">line types</a> are shown <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">here</a>.</li>
</ul>
<pre class="r"><code># Change the scatter plot line type;
# change point shape, size and fill color
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
        addRegLine=TRUE, regLineColor="darkred",
        linetype="dashed", shape=23, size=3, fill="blue")                  </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-line-type.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /></p>
</div>
<div id="scatter-plot-plot-with-multiple-groups" class="section level1">
<h1>Scatter plot plot with multiple groups</h1>
<p><span class="success">We will set color/shape by another variable (cyl)</span></p>
<pre class="r"><code># plot of variable &amp;#39;mpg&amp;#39; according to xName &amp;#39;wt&amp;#39;.
# The plot is colored by the groupName &amp;#39;cyl&amp;#39;
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
                    groupName="cyl")

# Change group colors
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, 
        groupName=&amp;#39;cyl&amp;#39;, size=3,
        backgroundColor="white",
        groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;, &amp;#39;#56B4E9&amp;#39;))  

# Use unique color for all groups
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, 
            groupName=&amp;#39;cyl&amp;#39;, size=3,
            backgroundColor="white", setColorByGroupName=FALSE)  </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-multiple-groups1.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-multiple-groups2.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-multiple-groups3.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /></p>
<pre class="r"><code># Add regression line and confidence interval
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
      groupName=&amp;#39;cyl&amp;#39;, size=3, backgroundColor="white",
      groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;, &amp;#39;#56B4E9&amp;#39;),
      addRegLine=TRUE, addConfidenceInterval=TRUE)  

# Extend the regression lines beyond the domain of the data
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, 
      groupName=&amp;#39;cyl&amp;#39;, size=3, backgroundColor="white",
      groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;, &amp;#39;#56B4E9&amp;#39;),
      addRegLine=TRUE, fullrange=TRUE)  

# Set point shape by groupName
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
      groupName=&amp;#39;cyl&amp;#39;, size=3, backgroundColor="white",
      groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;, &amp;#39;#56B4E9&amp;#39;),
      setShapeByGroupName=TRUE) </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-multiple-groups-with-regression-line1.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-multiple-groups-with-regression-line2.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-multiple-groups-with-regression-line3.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /></p>
</div>
<div id="customize-your-scatter-plot" class="section level1">
<h1>Customize your scatter plot</h1>
<div id="parameters" class="section level2">
<h2>Parameters</h2>
<p>The arguments that can be used to customize x and y axis are listed below :</p>
<table>
<thead>
<tr class="header">
<th align="left">Parameters</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>mainTitle</strong></td>
<td align="left">the title of the plot</td>
</tr>
<tr class="even">
<td align="left"><strong>mainTitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style (“italic”, “bold”, “bold.italic”) and the color of x and y axis titles. Default value is: mainTitleFont=c(14, “bold”, “black”).</td>
</tr>
<tr class="odd">
<td align="left"><strong>xShowTitle, yShowTitle</strong></td>
<td align="left">if TRUE, x and y axis titles will be shown. Set the value to FALSE to hide axis labels. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtitle, ytitle</strong></td>
<td align="left">x and y axis labels. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xtitleFont, ytitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis titles. Possible values for the <strong>style</strong>:“plain”, “italic”, “bold”, “bold.italic”. Color can be specified as an hexadecimal code (e.g: “#FFCC00”) or by the name (e.g : “red”, “green”). Default values are <code>xtitleFont=c(14,"bold", "black"), ytitleFont=c(14,"bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xlim, ylim</strong></td>
<td align="left">limit for the x and y axis. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xScale, yScale</strong></td>
<td align="left">x and y axis scales. Possible values : c(“none”, “log2”, “log10”). e.g: yScale=“log2”. Default values are <code>NULL</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xShowTickLabel, yShowTickLabel</strong></td>
<td align="left">if TRUE, x and y axis tick mark labels will be shown. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xTickLabelFont, yTickLabelFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis tick label fonts. Default value are <code>xTickLabelFont=c(12, "bold", "black"), yTickLabelFont=c(12, "bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtickLabelRotation, ytickLabelRotation</strong></td>
<td align="left">Rotation angle of x and y axis tick labels. Default value are <code>0</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>hideAxisTicks</strong></td>
<td align="left">if TRUE, x and y axis ticks are hidden. Default value is <code>FALSE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>axisLine</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the line type and the color of axis lines. Default value is <code>c(0.5, "solid", "#E5E5E5")</code>.</td>
</tr>
</tbody>
</table>
<p>For more details follow this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2.customize</a>.</p>
</div>
<div id="main-title-and-axis-labels" class="section level2">
<h2>Main title and axis labels</h2>
<pre class="r"><code># Change main title and axis titles
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
      mainTitle="Miles per gallon \n according to the weight",
      xtitle="Weight (lb/1000)", ytitle="Miles/(US) gallon")

# Customize title styles. Possible values for the font style :
  # &amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
    mainTitle="Miles per gallon \n according to the weight",
    xtitle="Weight (lb/1000)", ytitle="Miles/(US) gallon",
    mainTitleFont=c(14,"bold.italic", "red"),
    xtitleFont=c(14,"bold", "#993333"), 
    ytitleFont=c(14,"bold", "#993333"))

# Hide x an y axis titles
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
                xShowTitle=FALSE, yShowTitle=FALSE)               </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-main-title-and-axis-labels1.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-main-title-and-axis-labels2.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-main-title-and-axis-labels3.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /></p>
</div>
<div id="axis-ticks" class="section level2">
<h2>Axis ticks</h2>
<pre class="r"><code># Axis ticks labels and orientaion
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
          xShowTitle=FALSE, yShowTitle=FALSE,
          xTickLabelFont=c(14,"bold", "#993333"),
          yTickLabelFont=c(14,"bold", "#993333"),
          xtickLabelRotation=45, ytickLabelRotation=45)

# Hide axis tick labels
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
          xShowTitle=FALSE, yShowTitle=FALSE,
          xShowTickLabel=FALSE, yShowTickLabel=FALSE)

# Hide axis ticks
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
        xShowTitle=FALSE, yShowTitle=FALSE,
        xShowTickLabel=FALSE, yShowTickLabel=FALSE,
        hideAxisTicks=TRUE)

# AxisLine : a vector of length 3 indicating the size,
  #the line type and the color of axis lines
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, 
        axisLine=c(1, "solid", "darkblue"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-axis-ticks1.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-axis-ticks2.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-axis-ticks3.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-axis-ticks4.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="163.2" /></p>
</div>
<div id="background-and-colors" class="section level2">
<h2>Background and colors</h2>
<div id="change-scatter-plot-plot-background-and-point-colors" class="section level3">
<h3>Change scatter plot plot background and point colors</h3>
<pre class="r"><code># change background color to "white". Default is "gray"
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
                backgroundColor="white")

# Change background color to "lightblue" and grid color to "white"
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
          backgroundColor="lightblue", gridColor="white")

# Change point color
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
          backgroundColor="white", color=&amp;#39;#FFAAD4&amp;#39;)

# Remove grid; Remove Top and right border around the plot
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
          backgroundColor="white", color=&amp;#39;#FFAAD4&amp;#39;,
          removePanelGrid=TRUE,removePanelBorder=TRUE,
          axisLine=c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-background-color1.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-background-color2.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-background-color3.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-background-color4.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="163.2" /></p>
</div>
<div id="change-scatter-plot-color-according-to-the-group" class="section level3">
<h3>Change scatter plot color according to the group</h3>
<p><span class="warning">Colors can be specified as a hexadecimal RGB triplet, such as <code>"#FFCC00"</code> or by names (e.g : <code>"red"</code> ). You can also use other color scales, such as ones taken from the RColorBrewer package. The different <a href="https://www.sthda.com/english/english/wiki/colors-in-r">color systems</a> available in R have been described in detail <a href="https://www.sthda.com/english/english/wiki/colors-in-r">here</a>.<span></p>
<p><span class="success">To change <strong>scatter plot</strong> color according to the group, you have to specify the name of the data column containing the groups using the argument <code>groupName</code>. Use the argument <code>groupColors</code>, to specify colors by <code>hexadecimal</code> code or by <code>name</code>. In this case, the length of groupColors should be the same as the number of the groups. Use the argument <code>brewerPalette</code>, to specify colors using <code>RColorBrewer</code>palette.</span></p>
<pre class="r"><code># Change point color according to another variable
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, 
                size=3, mapping=aes(colour = qsec))                 

# change point color transparency (alpha) according 
# to another variable. alpha is the transparency degree of color. 
#The value can variate from 0 (total transparency) 
  # to 1 (no transparency)
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, size=3, 
                  mapping=aes(alpha = qsec), color="darkgreen")

#Change point color according to a factor variable (group)
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, 
                    size=3, groupName="cyl")
                    
#Change group colors using hexadecimal colors
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
              groupName="cyl", size=3,
              groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;))
                     
# Change group colors using brewer palette: "Paired"
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, size=3,
                    groupName="cyl", brewerPalette="Paired")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-scatter-plot-color1.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-scatter-plot-color2.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-scatter-plot-color3.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-scatter-plot-color4.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-scatter-plot-color5.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /></p>
<br/>
<div class="block">
<p>Color can also be changed by using names as follow :</p>
<pre class="r"><code># Change group colors using color names
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, size=3,
      groupName="cyl", 
      groupColors=c(&amp;#39;aquamarine3&amp;#39;,&amp;#39;chartreuse1&amp;#39;,&amp;#39;goldenrod1&amp;#39;))</code></pre>
</div>
<p><br/></p>
</div>
</div>
<div id="legend" class="section level2">
<h2>Legend</h2>
<div id="legend-position" class="section level3">
<h3>Legend position</h3>
<pre class="r"><code># Change the legend position to "top" 
  # (possible values: "left","top", "right", "bottom")
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, 
            groupName="cyl", legendPosition="top")

# legendPosition can be also a numeric vector c(x, y)
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
        groupName="cyl", legendPosition=c(0.8,0.2))

# Remove plot legend
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, 
                groupName="cyl", showLegend=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-legend-position1.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-legend-position2.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-legend-position3.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="240" /></p>
<p><span class="warning">It is also possible to position the legend inside the plotting area. You have to indicate the x, y coordinates of legend box. x and y values must be between 0 and 1. c(0,0) corresponds to <strong>“bottom left”</strong> and c(1,1) corresponds to <strong>“top right”</strong> position.</span></p>
</div>
<div id="legend-background-color-title-and-text-font-styles" class="section level3">
<h3>Legend background color, title and text font styles</h3>
<pre class="r"><code># Change legend background color, title and text font styles
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, 
    groupName="cyl",
    #legendPosition=c("right", "left","top", "bottom")
    legendPosition="right",
    #legendTitleFont=c(size, style, color)
    legendTitle="Dose (mg)", legendTitleFont=c(10, "bold", "blue"),
    #legendTextFont=c(size, style, color)
    legendTextFont=c(10, "bold.italic", "red"),
    #legendBackground: c(fill, lineSize, lineType, lineColor)
    legendBackground=c("lightblue", 0.5, "solid", "darkblue" )
    )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-legend-background-and-title.png" title="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." alt="Data visualization using ggplot2 scatter plot : tutorial on how to use ggplot2.scatterplot function to plot and customize quickly a scatter plot with R statistical software." width="288" /></p>
</div>
</div>
<div id="axis-scales" class="section level2">
<h2>Axis scales</h2>
<p>Possible values for x axis scale are “none”, “log2” and log10. Default value is “none”.</p>
<pre class="r"><code># Change y axis limit
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
                xlim=c(0,6) ,ylim=c(0,40))

# Log scale. yScale="log2". 
# Possible value="none", "log2" and "log10"
  #Default value is "none"
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;,
                xScale="log2", yScale="log2")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-axis-scale1.png" title="ggplot2 scatterplot" alt="ggplot2 scatterplot" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-axis-scale2.png" title="ggplot2 scatterplot" alt="ggplot2 scatterplot" width="240" /></p>
</div>
<div id="create-a-customized-plots-with-few-r-code" class="section level2">
<h2>Create a customized plots with few R code</h2>
<pre class="r"><code>#Customized scatterplot
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, size=3,
        addRegLine=TRUE, regLineColor="black", 
        addConfidenceInterval=TRUE,
        backgroundColor="white", xtitle="Weight (lb/1000)",
        ytitle="Miles/(US) gallon",
        mainTitle="Miles per gallon \n according to the weight")

# Remove grid; Remove Top and right border around the plot
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, size=3,
        addRegLine=TRUE, regLineColor="black",
        addConfidenceInterval=TRUE,
        backgroundColor="white", 
        xtitle="Weight (lb/1000)", ytitle="Miles/(US) gallon",
        mainTitle="Miles per gallon \n according to the weight",
        removePanelGrid=TRUE,removePanelBorder=TRUE,
        axisLine=c(0.5, "solid", "black"))
                       
# Change point color according to the factor cyl
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, size=3,
        groupName="cyl", 
        groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;,&amp;#39;#56B4E9&amp;#39;),
        addRegLine=TRUE, fullrange=TRUE, setShapeByGroupName=TRUE,
        backgroundColor="white", 
        xtitle="Weight (lb/1000)", ytitle="Miles/(US) gallon",
        mainTitle="Miles by weight")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-customized-plot1.png" title="ggplot2 scatterplot" alt="ggplot2 scatterplot" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-customized-plot2.png" title="ggplot2 scatterplot" alt="ggplot2 scatterplot" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-customized-plot3.png" title="ggplot2 scatterplot" alt="ggplot2 scatterplot" width="240" /></p>
</div>
</div>
<div id="faceting-split-a-plot-into-a-matrix-of-pannels" class="section level1">
<h1>Faceting : split a plot into a matrix of pannels</h1>
<p>The facet approach splits a plot into a matrix of panels. Each panel shows a different subset of the data.</p>
<div id="facet-with-one-variable" class="section level2">
<h2>Facet with one variable</h2>
<pre class="r"><code># Facet according to the supp variable
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;, yName="mpg",
            faceting=TRUE, facetingVarNames="cyl") 

# Change the direction. possible values are "vertical", "horizontal".
# default is vertical.
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;, yName="mpg",
            faceting=TRUE, facetingVarNames="cyl", 
            facetingDirection="horizontal") </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-facet-with-one-variable1.png" title="ggplot2 scatter plot and facet approch, one variable" alt="ggplot2 scatter plot and facet approch, one variable" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-facet-with-one-variable2.png" title="ggplot2 scatter plot and facet approch, one variable" alt="ggplot2 scatter plot and facet approch, one variable" width="240" /></p>
</div>
<div id="facet-with-two-variables" class="section level2">
<h2>Facet with two variables</h2>
<pre class="r"><code># Facet by two variables: cyl and vs.
#Rows are cyl and columns are vs
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;, yName="mpg",
                faceting=TRUE, facetingVarNames=c("cyl", "vs"))

# Facet by two variables: reverse the order of the 2 variables
# Rows are vs and columns are cyl
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;, yName="mpg",
                faceting=TRUE, facetingVarNames=c("vs", "cyl"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-facet-with-two-variable1.png" title="ggplot2 scatter plot and facet approch, two variables" alt="ggplot2 scatter plot and facet approch, two variables" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-facet-with-two-variable2.png" title="ggplot2 scatter plot and facet approch, two variables" alt="ggplot2 scatter plot and facet approch, two variables" width="240" /></p>
</div>
<div id="facet-scales" class="section level2">
<h2>Facet scales</h2>
<p>By default, all the panels have the same scale (<code>facetingScales="fixed"</code>). They can be made independent, by setting scales to <code>free</code>, <code>free_x</code>, or <code>free_y</code>.</p>
<pre class="r"><code>#Facet with free scales
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;, yName="mpg",
        faceting=TRUE, facetingVarNames=c("vs", "cyl"),
        facetingScales="free")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-facet-free-scale.png" title="ggplot2 scatter plot and facet approch, free scale" alt="ggplot2 scatter plot and facet approch, free scale" width="384" /></p>
<p><span class="success">As you can see in the above plot, y axis have different scales in the different panels.</span></p>
</div>
<div id="facet-label-apperance" class="section level2">
<h2>Facet label apperance</h2>
<pre class="r"><code># Change facet text font. Possible values for the font style:
  #&amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;, yName="mpg",
              faceting=TRUE, facetingVarNames=c("vs", "cyl"),
              facetingFont=c(12, &amp;#39;bold.italic&amp;#39;, "red"))

# Change the apperance of the rectangle around facet label
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;, yName="mpg",
            faceting=TRUE, facetingVarNames=c("vs", "cyl"),
            facetingRect=list(background="white", lineType="solid", 
                              lineColor="black", lineSize=1.5)
            )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-facet-label-apperance1.png" title="ggplot2 scatter plot and facet approch, facet label" alt="ggplot2 scatter plot and facet approch, facet label" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-scatter-plot-facet-label-apperance2.png" title="ggplot2 scatter plot and facet approch, facet label" alt="ggplot2 scatter plot and facet approch, facet label" width="240" /></p>
</div>
</div>
<div id="ggplot2.scatterplot-function" class="section level1">
<h1>ggplot2.scatterplot function</h1>
<div id="description" class="section level2">
<h2>Description</h2>
<p>Plot easily a scatter plot using <strong>easyGgplot2</strong> R package.</p>
</div>
<div id="usage" class="section level2">
<h2>usage</h2>
<pre class="r"><code>ggplot2.scatterplot(data, xName, yName, groupName=NULL,
        addRegLine=FALSE,regLineColor="blue",regLineSize=0.5,
        smoothingMethod=c("lm", "glm", "gam", "loess", "rlm"),
        addConfidenceInterval=FALSE, confidenceLevel= 0.95,
        confidenceIntervalFill="#C7C7C7",
        setColorByGroupName=TRUE, setShapeByGroupName=FALSE,
        groupColors=NULL, brewerPalette=NULL,...)</code></pre>
</div>
<div id="arguments" class="section level2">
<h2>Arguments</h2>
<table>
<thead>
<tr class="header">
<th align="left">Arguments</th>
<th align="left">Descriptions</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>data</strong></td>
<td align="left">Data frame. Columns are variables and rows are observations.</td>
</tr>
<tr class="even">
<td align="left"><strong>xName</strong></td>
<td align="left">The name of column containing x variable (i.e groups).</td>
</tr>
<tr class="odd">
<td align="left"><strong>yName</strong></td>
<td align="left">The name of column containing y variable.</td>
</tr>
<tr class="even">
<td align="left"><strong>groupName</strong></td>
<td align="left">The name of column containing group variable. This variable is used to color plot according to the group.</td>
</tr>
<tr class="odd">
<td align="left"><strong>addRegLine</strong></td>
<td align="left">If TRUE, regression line is added. Default value is FALSE.</td>
</tr>
<tr class="even">
<td align="left"><strong>regLineColor</strong></td>
<td align="left">Color of regression line. Default value is blue.</td>
</tr>
<tr class="odd">
<td align="left"><strong>regLineSize</strong></td>
<td align="left">Weight of regression line. Default value is 0.5.</td>
</tr>
<tr class="even">
<td align="left"><strong>smoothingMethod</strong></td>
<td align="left">Smoothing method (function) to use, eg. lm, glm, gam, loess, rlm. For datasets with n < 1000 default is loess. For datasets with 1000 or more observations defaults to gam. lm for linear smooths, glm for generalized linear smooths, loess for local smooths, gam fits a generalized additive model.</td>
</tr>
<tr class="odd">
<td align="left"><strong>addConfidenceInterval</strong></td>
<td align="left">Display confidence interval around smooth? (FALSE by default).</td>
</tr>
<tr class="even">
<td align="left"><strong>confidenceLevel</strong></td>
<td align="left">Level controlling confidence region. Default is 95%.</td>
</tr>
<tr class="odd">
<td align="left"><strong>confidenceIntervalFill</strong></td>
<td align="left">Fill color of confidence interval.</td>
</tr>
<tr class="even">
<td align="left"><strong>setColorByGroupName</strong></td>
<td align="left">If TRUE, points are colored according the groups. Default value is TRUE.</td>
</tr>
<tr class="odd">
<td align="left"><strong>setShapeByGroupName</strong></td>
<td align="left">If TRUE, point shapes are different according to the group. Default value is FALSE.</td>
</tr>
<tr class="even">
<td align="left"><strong>groupColors</strong></td>
<td align="left">Color of groups. groupColors should have the same length as groups.</td>
</tr>
<tr class="odd">
<td align="left"><strong>brewerPalette</strong></td>
<td align="left">This can be also used to indicate group colors. In this case the parameter groupColors should be NULL. e.g: brewerPalette=“Paired”.</td>
</tr>
<tr class="even">
<td align="left"><strong>….</strong></td>
<td align="left">Other parameters passed on to ggplot2.customize custom function or to geom_smooth and to geom_point functions from ggplot2 package.</td>
</tr>
</tbody>
</table>
<p><span class="warning">The other arguments which can be used are described at this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2 customize</a>. They are used to customize the plot (axis, title, background, color, legend, ….) generated <strong>using ggplot2</strong> or <strong>easyGgplot2</strong> R package.</span></p>
</div>
<div id="examples" class="section level2">
<h2>Examples</h2>
<pre class="r"><code>df <- mtcars
ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, size=3,
        mainTitle="Miles per gallon \n according to the weight",
        xtitle="Weight (lb/1000)", ytitle="Miles/(US) gallon")

#Or use this
plot<-ggplot2.scatterplot(data=df, xName=&amp;#39;wt&amp;#39;,yName=&amp;#39;mpg&amp;#39;, size=3)
plot<-ggplot2.customize(plot, 
          mainTitle="Miles per gallon \n according to the weight",
          xtitle="Weight (lb/1000)", ytitle="Miles/(US) gallon")
print(plot)</code></pre>
<p><br/></p>
</div>
</div>
<div id="easy-ggplot2-ebook" class="section level1">
<h1>Easy ggplot2 ebook</h1>
<p><span class="success">Note that an eBook is available on <strong>easyGgplot2</strong> package <a href="https://www.sthda.com/english/english/download/download-4+easy-ggplot2-book.php">here</a>.</span></p>
<div class="block">
<p>By Alboukadel Kassambara</p>
<p>Copyright 2014 Alboukadel Kassambara. All rights reserved.</p>
<p>Published by STHDA (<a href="https://www.sthda.com/english">https://www.sthda.com/english</a>).</p>
<p>September 2014 : First edition.</p>
<p><strong>Licence</strong> : This document is under creative commons licence (<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">http://creativecommons.org/licenses/by-nc-sa/3.0/</a>).</p>
<p><strong>Contact</strong> : Alboukadel Kassambara <a href="mailto:alboukadel.kassambara@gmail.com">alboukadel.kassambara@gmail.com</a></p>
</div>
<p><br/></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning">This analysis was performed using R (ver. 3.1.0), easyGgplot2 (ver 1.0.0) and ggplot2 (ver 1.0.0).</span></p>
<ul>
<li><a href="http://docs.ggplot2.org/current/">ggplot2 online documentation</a></li>
<li><a href="http://www.cookbook-r.com/Graphs/">Cookbook for R</a></li>
</ul>
</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 Feb 2015 21:10:05 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[ggplot2.multiplot : Put multiple graphs on the same page using ggplot2]]></title>
			<link>https://www.sthda.com/english/wiki/ggplot2-multiplot-put-multiple-graphs-on-the-same-page-using-ggplot2</link>
			<guid>https://www.sthda.com/english/wiki/ggplot2-multiplot-put-multiple-graphs-on-the-same-page-using-ggplot2</guid>
			<description><![CDATA[<!-- START HTML -->

            
  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">


<div id="TOC">
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#install-and-load-easyggplot2-package">Install and load easyGgplot2 package</a></li>
<li><a href="#examples">Examples</a></li>
<li><a href="#ggplot2.multiplot-function">ggplot2.multiplot function</a><ul>
<li><a href="#description">Description</a></li>
<li><a href="#usage">usage</a></li>
<li><a href="#arguments">Arguments</a></li>
</ul></li>
<li><a href="#easy-ggplot2-ebook">Easy ggplot2 ebook</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<div id="introduction" class="section level1">
<h1>Introduction</h1>
<p><strong>ggplot2.multiplot</strong> is an easy to use function to put <strong>multiple graphs</strong> on the same page using <strong>R statistical software</strong> and <strong>ggplot2</strong> plotting methods. This function is from <a href="https://www.sthda.com/english/english/wiki/easyggplot2"><strong>easyGgplot2</strong></a> package.</p>

</div>
<div id="install-and-load-easyggplot2-package" class="section level1">
<h1>Install and load easyGgplot2 package</h1>
<p><strong>easyGgplot2</strong> R package can be installed as follow :</p>
<pre class="r"><code>install.packages("devtools")
library(devtools)
install_github("easyGgplot2", "kassambara")</code></pre>
<p>Load the package using this R code :</p>
<pre class="r"><code>library(easyGgplot2)</code></pre>
</div>
<div id="examples" class="section level1">
<h1>Examples</h1>
<pre class="r"><code># data.frame
df <- ToothGrowth
# Custom box plot with centered dot plot
plot1<-ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                groupName=&amp;#39;dose&amp;#39;,
                addDot=TRUE, dotSize=1, showLegend=FALSE)

# Custom dot plot with centered dot plot
plot2<-ggplot2.dotplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                groupName=&amp;#39;dose&amp;#39;,showLegend=FALSE)

# Custom strip chart with centered dot plot
plot3<-ggplot2.stripchart(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                      groupName=&amp;#39;dose&amp;#39;, showLegend=FALSE)

# Notched box plot
plot4<-ggplot2.boxplot(data=df, xName=&amp;#39;dose&amp;#39;,yName=&amp;#39;len&amp;#39;,
                notch=TRUE)

# Multiple graphs on the same page
ggplot2.multiplot(plot1,plot2,plot3,plot4, cols=2)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-multiplot-multiple-plot.png" title="Data visualization using ggplot2 : tutorial on how to put multiple graphs on the same page" alt="Data visualization using ggplot2 : tutorial on how to put multiple graphs on the same page" width="480" /></p>
</div>
<div id="ggplot2.multiplot-function" class="section level1">
<h1>ggplot2.multiplot function</h1>
<div id="description" class="section level2">
<h2>Description</h2>
<p>Put multiple graphs on the same page</p>
</div>
<div id="usage" class="section level2">
<h2>usage</h2>
<pre class="r"><code>library(easyGgplot2)
ggplot2.multiplot(..., plotlist=NULL, cols=2)</code></pre>
</div>
<div id="arguments" class="section level2">
<h2>Arguments</h2>
<table>
<thead>
<tr class="header">
<th align="left">Arguments</th>
<th align="left">Descriptions</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>…, plotList</strong></td>
<td align="left">List of ggplot2 objects separated by a comma. (e.g: plot1, plot2, plot3)</td>
</tr>
<tr class="even">
<td align="left"><strong>cols</strong></td>
<td align="left">Number of columns in layout</td>
</tr>
</tbody>
</table>
<p><br/></p>
</div>
</div>
<div id="easy-ggplot2-ebook" class="section level1">
<h1>Easy ggplot2 ebook</h1>
<p><span class="success">Note that an eBook is available on <strong>easyGgplot2</strong> package <a href="https://www.sthda.com/english/english/download/download-4+easy-ggplot2-book.php">here</a>.</span></p>
<div class="block">
<p>By Alboukadel Kassambara</p>
<p>Copyright 2014 Alboukadel Kassambara. All rights reserved.</p>
<p>Published by STHDA (<a href="https://www.sthda.com/english">https://www.sthda.com/english</a>).</p>
<p>September 2014 : First edition.</p>
<p><strong>Licence</strong> : This document is under creative commons licence (<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">http://creativecommons.org/licenses/by-nc-sa/3.0/</a>).</p>
<p><strong>Contact</strong> : Alboukadel Kassambara <a href="mailto:alboukadel.kassambara@gmail.com">alboukadel.kassambara@gmail.com</a></p>
</div>
<p><br/></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning">This analysis was performed using R (ver. 3.1.0), easyGgplot2 (ver 1.0.0) and ggplot2 (ver 1.0.0).</span></p>
<ul>
<li><a href="http://docs.ggplot2.org/current/">ggplot2 online documentation</a></li>
<li><a href="http://www.cookbook-r.com/Graphs/">Cookbook for R</a></li>
</ul>
</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 Feb 2015 21:08:32 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[ggplot2 histogram : Easy histogram graph with ggplot2 R package]]></title>
			<link>https://www.sthda.com/english/wiki/ggplot2-histogram-easy-histogram-graph-with-ggplot2-r-package</link>
			<guid>https://www.sthda.com/english/wiki/ggplot2-histogram-easy-histogram-graph-with-ggplot2-r-package</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">


<div id="TOC">
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#install-and-load-easyggplot2-package">Install and load easyGgplot2 package</a></li>
<li><a href="#data-format">Data format</a></li>
<li><a href="#basic-histograms">Basic histograms</a></li>
<li><a href="#change-the-histogram-orientation">Change the histogram orientation</a></li>
<li><a href="#add-mean-line-and-density-curve">Add mean line and density curve</a></li>
<li><a href="#change-the-line-type-of-the-histogram-plot">Change the line type of the histogram plot</a></li>
<li><a href="#histogram-plot-with-multiple-groups">Histogram plot with multiple groups</a></li>
<li><a href="#customize-your-histogram-plot">Customize your histogram plot</a><ul>
<li><a href="#parameters">Parameters</a></li>
<li><a href="#main-title-and-axis-labels">Main title and axis labels</a></li>
<li><a href="#axis-ticks">Axis ticks</a></li>
<li><a href="#background-and-colors">Background and colors</a><ul>
<li><a href="#change-histogram-plot-background-and-fill-colors">Change histogram plot background and fill colors</a></li>
<li><a href="#fill-the-histogram-by-count-value">Fill the histogram by count value</a></li>
<li><a href="#change-histogram-plot-color-according-to-the-group">Change histogram plot color according to the group</a></li>
</ul></li>
<li><a href="#legend">Legend</a><ul>
<li><a href="#legend-position">Legend position</a></li>
<li><a href="#legend-background-color-title-and-text-font-styles">Legend background color, title and text font styles</a></li>
</ul></li>
<li><a href="#axis-scales">Axis scales</a></li>
<li><a href="#create-a-customized-plots-with-few-r-code">Create a customized plots with few R code</a></li>
</ul></li>
<li><a href="#facet-split-a-plot-into-a-matrix-of-panels">Facet : split a plot into a matrix of panels</a><ul>
<li><a href="#facet-with-one-variable">Facet with one variable</a></li>
<li><a href="#facet-with-two-variables">Facet with two variables</a></li>
<li><a href="#facet-scales">Facet scales</a></li>
<li><a href="#facet-label-apperance">Facet label apperance</a></li>
</ul></li>
<li><a href="#ggplot2.histogram-function">ggplot2.histogram function</a><ul>
<li><a href="#description">Description</a></li>
<li><a href="#usage">usage</a></li>
<li><a href="#arguments">Arguments</a></li>
<li><a href="#examples">Examples</a></li>
</ul></li>
<li><a href="#easy-ggplot2-ebook">Easy ggplot2 ebook</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<div id="introduction" class="section level1">
<h1>Introduction</h1>
<p><strong>ggplot2.histogram</strong> is an easy to use function for plotting <strong>histograms</strong> using <strong>ggplot2</strong> package and <strong>R statistical software</strong>. In this <strong>ggplot2 tutorial</strong> we will see how to make a <strong>histogram</strong> and to customize the graphical parameters including <strong>main title</strong>, <strong>axis labels</strong>, <strong>legend</strong>, <strong>background</strong> and <strong>colors</strong>. ggplot2.histogram function is from <a href="https://www.sthda.com/english/english/wiki/easyggplot2"><strong>easyGgplot2</strong></a> R package. An R script is available in the next section to install the package.</p>
<p>At the end of this <strong>tutorial</strong> you will be able to draw, with few R code, the following plot:</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-demo.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="336" /></p>

<p><span class="warning"><strong>ggplot2.histogram</strong> function is described in detail at the end of this document.</span></p>
</div>
<div id="install-and-load-easyggplot2-package" class="section level1">
<h1>Install and load easyGgplot2 package</h1>
<p><strong>easyGgplot2</strong> R package can be installed as follow :</p>
<pre class="r"><code>install.packages("devtools")
library(devtools)
install_github("easyGgplot2", "kassambara")</code></pre>
<p>Load the package using this R code :</p>
<pre class="r"><code>library(easyGgplot2)</code></pre>
</div>
<div id="data-format" class="section level1">
<h1>Data format</h1>
<p><span class="success">The data must be a numeric vector or a data.frame (columns are variables and rows are observations).</span></p>
<p>weight data, from <strong>easyGgplot2</strong> package, will be used in the following examples.</p>
<pre class="r"><code># create a numeric vector
numVector<-rnorm(100)
head(numVector)</code></pre>
<pre><code>## [1]  0.5738  1.1956 -0.1904  0.4465  0.2567 -1.6642</code></pre>
<pre class="r"><code># data.frame
head(weight)</code></pre>
<pre><code>##      sex weight
## 1 Female  63.79
## 2 Female  65.28
## 3 Female  66.08
## 4 Female  62.65
## 5 Female  65.43
## 6 Female  65.51</code></pre>
<br/>

<div class="block">
weight data contain the weight of 400 people (200 females and 200 males).
</div>
<p><br/></p>
</div>
<div id="basic-histograms" class="section level1">
<h1>Basic histograms</h1>
<pre class="r"><code># Histogram from a single numeric vector 
# ggplot2.histogram(data=numVector)

# Basic histogram plot from the vector "weight"
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;)

# Change the width of bars
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;, binwidth=0.1)

# Change y axis values to density
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;, scale="density")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-basic-histogram1.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-basic-histogram2.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-basic-histogram3.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /></p>
</div>
<div id="change-the-histogram-orientation" class="section level1">
<h1>Change the histogram orientation</h1>
<pre class="r"><code># Horizontal histogram plot
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
                  orientation="horizontal")

# y Axis reversed
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
                  orientation="yAxisReversed")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-orientation1.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-orientation2.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /></p>
</div>
<div id="add-mean-line-and-density-curve" class="section level1">
<h1>Add mean line and density curve</h1>
<pre class="r"><code># Add mean line to the histogram plot.
# Change fill color and line color
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
                  fill="white", color="black",
                  addMeanLine=TRUE, meanLineColor="red",
                  meanLineType="dashed", meanLineSize=1)

# Add density curve
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
                  fill="white", color="black",
                  addDensityCurve=TRUE, densityFill=&amp;#39;#FF6666&amp;#39;)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-mean-line-and-density-curve1.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-mean-line-and-density-curve2.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="240" /></p>
</div>
<div id="change-the-line-type-of-the-histogram-plot" class="section level1">
<h1>Change the line type of the histogram plot</h1>
<p><span class="warning">Different <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">point shapes</a> and <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">line types</a> can be used in the plot. By default, ggplot2 uses solid line type and circle shape.</span></p>
<ul>
<li>The different <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">point shapes</a> in R are described <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">here</a>.</li>
<li>The available <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">line types</a> are shown <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">here</a>.</li>
</ul>
<pre class="r"><code>#Change the histogram line color and line type
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
                  fill="white", color="black",
                  linetype="longdash")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-line-type.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="288" /></p>
</div>
<div id="histogram-plot-with-multiple-groups" class="section level1">
<h1>Histogram plot with multiple groups</h1>
<pre class="r"><code># Multiple histograms on the same plot
# Color the histogram plot by the groupName "sex"
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
        groupName=&amp;#39;sex&amp;#39;, legendPosition="top")

# Histogram plots with semi-transparent fill.
# alpha is the transparency of the overlaid color
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
        groupName=&amp;#39;sex&amp;#39;, legendPosition="top",
        alpha=0.5 )

# Histogram plots with mean lines
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
    groupName=&amp;#39;sex&amp;#39;, legendPosition="top",
    alpha=0.5, addDensity=TRUE,
    addMeanLine=TRUE, meanLineColor="white", meanLineSize=1.5)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-multiple-groups1.png" title="Histogram with multiple groups" alt="Histogram with multiple groups" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-multiple-groups2.png" title="Histogram with multiple groups" alt="Histogram with multiple groups" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-multiple-groups3.png" title="Histogram with multiple groups" alt="Histogram with multiple groups" width="240" /></p>
<p><span class="warning"> You can change the position adjustment to use for overlapping points on the layer. Possible values for the argument <code>position</code> is “identity”, “stack”, “dodge”. This is shown in the following histograms. </span></p>
<pre class="r"><code># Default value of position is "identity"
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
        groupName=&amp;#39;sex&amp;#39;, legendPosition="top",
        alpha=0.5, position="identity")

# Interleaved histograms
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
        groupName=&amp;#39;sex&amp;#39;, legendPosition="top",
        alpha=0.5, position="dodge")

#stacked histograms
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
        groupName=&amp;#39;sex&amp;#39;, legendPosition="top",
        alpha=0.5, position="stack")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-multiple-histograms-position1.png" title="Histogram with multiple groups" alt="Histogram with multiple groups" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-multiple-histograms-position2.png" title="Histogram with multiple groups" alt="Histogram with multiple groups" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-multiple-histograms-position3.png" title="Histogram with multiple groups" alt="Histogram with multiple groups" width="240" /></p>
</div>
<div id="customize-your-histogram-plot" class="section level1">
<h1>Customize your histogram plot</h1>
<div id="parameters" class="section level2">
<h2>Parameters</h2>
<p>The arguments that can be used to customize titles and x and y axis are listed below :</p>
<table>
<thead>
<tr class="header">
<th align="left">Parameters</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>mainTitle</strong></td>
<td align="left">the title of the plot</td>
</tr>
<tr class="even">
<td align="left"><strong>mainTitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style (“italic”, “bold”, “bold.italic”) and the color of x and y axis titles. <code>Default value is: mainTitleFont=c(14, "bold", "black")</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xShowTitle, yShowTitle</strong></td>
<td align="left">if TRUE, x and y axis titles will be shown. Set the value to FALSE to hide axis labels. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtitle, ytitle</strong></td>
<td align="left">x and y axis labels. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xtitleFont, ytitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis titles. Possible values for the <strong>style</strong>:“plain”, “italic”, “bold”, “bold.italic”. <strong>Color</strong> can be specified as an hexadecimal code (e.g: “#FFCC00”) or by the name (e.g : “red”, “green”). Default values are <code>xtitleFont=c(14,"bold", "black"), ytitleFont=c(14,"bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xlim, ylim</strong></td>
<td align="left">limit for the x and y axis. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xScale, yScale</strong></td>
<td align="left">x and y axis scales. Possible values : c(“none”, “log2”, “log10”). e.g: yScale=“log2”. Default values are <code>NULL</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xShowTickLabel, yShowTickLabel</strong></td>
<td align="left">if TRUE, x and y axis tick mark labels will be shown. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xTickLabelFont, yTickLabelFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis tick label fonts. Default value are <code>xTickLabelFont=c(12, "bold", "black"), yTickLabelFont=c(12, "bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtickLabelRotation, ytickLabelRotation</strong></td>
<td align="left">Rotation angle of x and y axis tick labels. Default value are <code>0</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>hideAxisTicks</strong></td>
<td align="left">if TRUE, x and y axis ticks are hidden. Default value is <code>FALSE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>axisLine</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the line type and the color of axis lines. Default value is <code>c(0.5, "solid", "#E5E5E5")</code>.</td>
</tr>
</tbody>
</table>
<p>For more details follow this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2.customize</a>.</p>
</div>
<div id="main-title-and-axis-labels" class="section level2">
<h2>Main title and axis labels</h2>
<pre class="r"><code># basic plot
plot<-ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;)
print(plot)

# Change main title and axis titles
ggplot2.customize(plot, mainTitle="Weight histo.",
                  xtitle="Weight (Kg)", ytitle="Histogram")

# Customize title styles. Possible values for the font style :
  # &amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.customize(plot,  mainTitle="Weight histo.",
                  mainTitleFont=c(14,"bold.italic", "red"),
                  xtitle="Weight (Kg)", ytitle="Histogram",
                  xtitleFont=c(14,"bold", "#993333"), 
                  ytitleFont=c(14,"bold", "#993333"))

# Hide x an y axis titles
ggplot2.customize(plot, xShowTitle=FALSE, yShowTitle=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-main-title-and-axis-labels1.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-main-title-and-axis-labels2.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-main-title-and-axis-labels3.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-main-title-and-axis-labels4.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /></p>
</div>
<div id="axis-ticks" class="section level2">
<h2>Axis ticks</h2>
<pre class="r"><code># Axis ticks labels and orientaion
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
                xShowTitle=FALSE, yShowTitle=FALSE,
                xTickLabelFont=c(14,"bold", "#993333"),
                yTickLabelFont=c(14,"bold", "#993333"),
                xtickLabelRotation=45, ytickLabelRotation=45)

# Hide axis tick labels
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
                xShowTitle=FALSE, yShowTitle=FALSE,
                xShowTickLabel=FALSE, yShowTickLabel=FALSE)

# Hide axis ticks
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
                xShowTitle=FALSE, yShowTitle=FALSE,
                xShowTickLabel=FALSE, yShowTickLabel=FALSE,
                hideAxisTicks=TRUE)

# AxisLine : a vector of length 3 indicating the size,
  #the line type and the color of axis lines
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
                  axisLine=c(1, "solid", "darkblue"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-axis-ticks1.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-axis-ticks2.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-axis-ticks3.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-axis-ticks4.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /></p>
</div>
<div id="background-and-colors" class="section level2">
<h2>Background and colors</h2>
<div id="change-histogram-plot-background-and-fill-colors" class="section level3">
<h3>Change histogram plot background and fill colors</h3>
<pre class="r"><code># Change background color to "white". Default is "gray"
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
        backgroundColor="white")

# Change background color to "lightblue" and grid color to "white"
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
        backgroundColor="lightblue", gridColor="white")

#Change plot fill color
#color =  color of the histogram border
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
         backgroundColor="white", color="black", fill=&amp;#39;#FFAAD4&amp;#39;)

# Remove grid; remove top and right borders around the plot;
# change  axis lines
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
        backgroundColor="white", color="black", fill=&amp;#39;#FFAAD4&amp;#39;,
        removePanelGrid=TRUE,removePanelBorder=TRUE,
        axisLine=c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-background-color1.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-background-color2.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-background-color3.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-background-color4.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="163.2" /></p>
</div>
<div id="fill-the-histogram-by-count-value" class="section level3">
<h3>Fill the histogram by count value</h3>
<pre class="r"><code># Fill the histogram according to the count value
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;)+
   geom_histogram(aes(fill = ..count..))
    
# Change the scale
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;)+
  geom_histogram(aes(fill = ..count..))+
   scale_fill_gradient("Count", low = "green", high = "red")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-fill-histogram-by-count1.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-fill-histogram-by-count2.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="240" /></p>
</div>
<div id="change-histogram-plot-color-according-to-the-group" class="section level3">
<h3>Change histogram plot color according to the group</h3>
<p><span class="warning">Colors can be specified as a hexadecimal RGB triplet, such as <code>"#FFCC00"</code> or by names (e.g : <code>"red"</code> ). You can also use other color scales, such as ones taken from the RColorBrewer package. The different <a href="https://www.sthda.com/english/english/wiki/colors-in-r">color systems</a> available in R have been described in detail <a href="https://www.sthda.com/english/english/wiki/colors-in-r">here</a>.<span></p>
<p><span class="success">To change <strong>histogram plot</strong> color according to the group, you have to specify the name of the data column containing the groups using the argument <code>groupName</code>. Use the argument <code>groupColors</code>, to specify colors by <code>hexadecimal</code> code or by <code>name</code>. In this case, the length of groupColors should be the same as the number of the groups. Use the argument <code>brewerPalette</code>, to specify colors using <code>RColorBrewer</code>palette.</span></p>
<pre class="r"><code># Change group colors using hexadecimal colors
# alpha is the transparency level of overlaid color. 
  #The value can variate from 0 (total transparency) 
  #to 1 (no transparency)
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
                legendPosition="top",
                groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;), alpha=0.5 )

# Change group colors using brewer palette: "Paired"
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
                legendPosition="top",
                brewerPalette="Paired",alpha=0.5)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-histogram-color1.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-histogram-color2.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="240" /></p>
<br/>
<div class="block">
<p>Color can also be changed by using names as follow :</p>
<pre class="r"><code>#Change group colors using color names
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
      groupName=&amp;#39;sex&amp;#39;, groupColors=c(&amp;#39;aquamarine3&amp;#39;,&amp;#39;goldenrod1&amp;#39;),
      alpha=0.5 )</code></pre>
</div>
<p><br/></p>
</div>
</div>
<div id="legend" class="section level2">
<h2>Legend</h2>
<div id="legend-position" class="section level3">
<h3>Legend position</h3>
<pre class="r"><code># Change the legend position to "top" 
  # (possible values: "left","top", "right", "bottom")
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;, 
                groupName=&amp;#39;sex&amp;#39;, alpha=0.5,
                legendPosition="top")

# legendPosition can be also a numeric vector c(x, y)
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
                groupName=&amp;#39;sex&amp;#39;, alpha=0.5,
                legendPosition=c(0.8,0.2))

#Remove legend
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
                groupName=&amp;#39;sex&amp;#39;, alpha=0.5,
                showLegend=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-legend-position1.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-legend-position2.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-legend-position3.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="240" /></p>
<p><span class="warning">It is also possible to position the legend inside the plotting area. You have to indicate the x, y coordinates of legend box. x and y values must be between 0 and 1. <code>c(0,0)</code> corresponds to <code>"bottom left"</code> and <code>c(1,1)</code> corresponds to <code>"top right"</code> position.</span></p>
</div>
<div id="legend-background-color-title-and-text-font-styles" class="section level3">
<h3>Legend background color, title and text font styles</h3>
<pre class="r"><code># Change legend background color, title and text font styles
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;, 
        groupName=&amp;#39;sex&amp;#39;, alpha=0.5,
        # legendTitleFont=c(size, style, color)
        legendTitle="Groups", legendTitleFont=c(10, "bold", "blue"),
        #legendTextFont=c(size, style, color)
        legendTextFont=c(10, "bold.italic", "red"),
        #legendBackground: c(fill, lineSize, lineType, lineColor)
        legendBackground=c("lightblue", 0.5, "solid", "darkblue" )
        )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-legend-background-and-title.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="288" /></p>
</div>
</div>
<div id="axis-scales" class="section level2">
<h2>Axis scales</h2>
<p>Possible values for x axis scale are “none”, “log2” and log10. Default value is “none”.</p>
<pre class="r"><code># Change x axis limit
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
                groupName=&amp;#39;sex&amp;#39;, alpha=0.5,
                showLegend=FALSE, xlim=c(60,72))

# x Log scale. Possible values="none", "log2" and "log10"
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
                groupName=&amp;#39;sex&amp;#39;, alpha=0.5,
                showLegend=FALSE, xScale="log2")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-axis-scale1.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-axis-scale2.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="240" /></p>
</div>
<div id="create-a-customized-plots-with-few-r-code" class="section level2">
<h2>Create a customized plots with few R code</h2>
<pre class="r"><code># basic plot
plot<-ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
              addMeanLine=TRUE, showLegend=FALSE,
              groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;), alpha=0.5,
              backgroundColor="white")
#print(plot)

# Customized histogram
plot<-ggplot2.customize(plot, xtitle="Weight (Kg)", ytitle="Count",
                showLegend=FALSE, 
                mainTitle="Weight histogram \nby sex")                
print(plot)


# Remove grid; Remove Top and right border around the plot 
# add density curve and mean line
ggplot2.customize(plot,
        removePanelGrid=TRUE,removePanelBorder=TRUE,
        axisLine=c(0.5, "solid", "black"),
        addDensity=TRUE, showLegend=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-customized-plot1.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-customized-plot2.png" title="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" alt="r data visualization with ggplot2 histogram  : tutorial on how to use ggplot2.histogram function to easily make histograms in R statistical software" width="240" /></p>
<p><span class="success">The argument alpha is used to specify the transparency of colors.</span></p>
</div>
</div>
<div id="facet-split-a-plot-into-a-matrix-of-panels" class="section level1">
<h1>Facet : split a plot into a matrix of panels</h1>
<p>The facet approach splits a plot into a matrix of panels. Each panel shows a different subset of the data.</p>
<div id="facet-with-one-variable" class="section level2">
<h2>Facet with one variable</h2>
<pre class="r"><code># Facet by "sex" variable
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
         groupName=&amp;#39;sex&amp;#39;, legendPosition="top",
        faceting=TRUE, facetingVarNames="sex") 

# Change the direction. possible values are "vertical", horizontal".
# default is vertical.
ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,
        groupName=&amp;#39;sex&amp;#39;, legendPosition="top",
        faceting=TRUE, facetingVarNames="sex",
        facetingDirection="horizontal") </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-facet-with-one-variable1.png" title="ggplot2 histogram and facet approch, one variable" alt="ggplot2 histogram and facet approch, one variable" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-facet-with-one-variable2.png" title="ggplot2 histogram and facet approch, one variable" alt="ggplot2 histogram and facet approch, one variable" width="240" /></p>
</div>
<div id="facet-with-two-variables" class="section level2">
<h2>Facet with two variables</h2>
<p>The <strong>mtcars</strong> data is used in the following examples.</p>
<pre class="r"><code>data(mtcars)
head(mtcars)</code></pre>
<pre><code>##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1</code></pre>
<p><span class="success"> mtcars (Motor Trend Car Road Tests) comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles.</span></p>
<pre class="r"><code># Facet by two variables: vs and am.
# Rows are vs and columns are am
ggplot2.histogram(data=mtcars, xName=&amp;#39;mpg&amp;#39;, groupName=&amp;#39;vs&amp;#39;,
        legendPosition="top",
        faceting=TRUE, facetingVarNames=c("vs", "am"))

#Facet by two variables: reverse the order of the 2 variables
#Rows are am and columns are vs
ggplot2.histogram(data=mtcars, xName=&amp;#39;mpg&amp;#39;, groupName=&amp;#39;vs&amp;#39;,
        legendPosition="top",
        faceting=TRUE, facetingVarNames=c("am", "vs"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-facet-with-two-variables1.png" title="ggplot2 histogram and facet approch, two variables" alt="ggplot2 histogram and facet approch, two variables" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-facet-with-two-variables2.png" title="ggplot2 histogram and facet approch, two variables" alt="ggplot2 histogram and facet approch, two variables" width="240" /></p>
</div>
<div id="facet-scales" class="section level2">
<h2>Facet scales</h2>
<p>By default, all the panels have the same scale (<code>facetingScales="fixed"</code>). They can be made independent, by setting scales to <code>free</code>, <code>free_x</code>, or <code>free_y</code>.</p>
<pre class="r"><code># Facet with free scales
ggplot2.histogram(data=mtcars, xName=&amp;#39;mpg&amp;#39;, groupName=&amp;#39;vs&amp;#39;,
      legendPosition="top",
      faceting=TRUE, facetingVarNames=c("vs", "am"),
      facetingScales="free")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-facet-free-scale.png" title="ggplot2 histogram and facet approch, free scale" alt="ggplot2 histogram and facet approch, free scale" width="288" /></p>
<p><span class="success"> As you can see in the above plot, y axis have different scales in the different panels.</span></p>
</div>
<div id="facet-label-apperance" class="section level2">
<h2>Facet label apperance</h2>
<pre class="r"><code># Change facet text font. Possible values for the font style:
  #&amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.histogram(data=mtcars, xName=&amp;#39;mpg&amp;#39;, groupName=&amp;#39;vs&amp;#39;,
        legendPosition="top",
        faceting=TRUE, facetingVarNames=c("vs", "am"),
        facetingFont=c(12, &amp;#39;bold.italic&amp;#39;, "red"))

# Change the apperance of the rectangle around facet label
ggplot2.histogram(data=mtcars, xName=&amp;#39;mpg&amp;#39;, groupName=&amp;#39;vs&amp;#39;,
        legendPosition="top",
        faceting=TRUE, facetingVarNames=c("vs", "am"),
        facetingRect=list(background="white", lineType="solid",
                      lineColor="black", lineSize=1.5)
        )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-facet-label-apperance1.png" title="ggplot2 histogram and facet approch, facet label" alt="ggplot2 histogram and facet approch, facet label" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-histogram-facet-label-apperance2.png" title="ggplot2 histogram and facet approch, facet label" alt="ggplot2 histogram and facet approch, facet label" width="240" /></p>
</div>
</div>
<div id="ggplot2.histogram-function" class="section level1">
<h1>ggplot2.histogram function</h1>
<div id="description" class="section level2">
<h2>Description</h2>
<p>Plot easily a histogram plot with R package <strong>easyGgplot2</strong>.</p>
</div>
<div id="usage" class="section level2">
<h2>usage</h2>
<pre class="r"><code>ggplot2.histogram(data, xName=NULL, groupName=NULL,
        position=c("identity", "stack", "dodge"),
        addMeanLine=FALSE, meanLineColor=NULL,
        meanLineType="dashed", meanLineSize=1,
        addDensityCurve=FALSE, densityFill="#FF6666",
        densityAlpha=0.2, 
        densityLineType="solid", densityLineColor="#2F2F2F",
        scale=c("frequency", "density"), 
        groupColors=NULL, brewerPalette=NULL,...)</code></pre>
</div>
<div id="arguments" class="section level2">
<h2>Arguments</h2>
<table>
<thead>
<tr class="header">
<th align="left">Arguments</th>
<th align="left">Descriptions</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>data</strong></td>
<td align="left">data.frame or a numeric vector. Columns are variables and rows are observations.</td>
</tr>
<tr class="even">
<td align="left"><strong>xName</strong></td>
<td align="left">The name of column containing x variable. Default value is NULL.</td>
</tr>
<tr class="odd">
<td align="left"><strong>groupName</strong></td>
<td align="left">The name of column containing group variable. This variable is used to color plot according to the group.</td>
</tr>
<tr class="even">
<td align="left"><strong>position</strong></td>
<td align="left">Change the position adjustment to use for overlapping points on the layer. Possible values for the argument position is “identity”, “stack”, “dodge”. Default value is identity.</td>
</tr>
<tr class="odd">
<td align="left"><strong>addMeanLine</strong></td>
<td align="left">If TRUE, the mean line is added on the plot for each group. Default value is FALSE.</td>
</tr>
<tr class="even">
<td align="left"><strong>meanLineColor, meanLineType, meanLineSize</strong></td>
<td align="left">mean line color, type and size.</td>
</tr>
<tr class="odd">
<td align="left"><strong>addDensityCurve</strong></td>
<td align="left">If true, add density curve. Default value is FALSE.</td>
</tr>
<tr class="even">
<td align="left"><strong>densityFill</strong></td>
<td align="left">The fill color of density plot. The value is considered only when groupName=NULL. If groupName is specified, density curves are colored according groupColors or brewerPalette.</td>
</tr>
<tr class="odd">
<td align="left"><strong>densityAlpha</strong></td>
<td align="left">Degree of transparency of overlaid colors for density curves. Default is 0.2 (20%).</td>
</tr>
<tr class="even">
<td align="left"><strong>densityLineType, densityLineColor</strong></td>
<td align="left">Line type and color for density curve.</td>
</tr>
<tr class="odd">
<td align="left"><strong>scale</strong></td>
<td align="left">Indicate whether y axis values are density or frequency. Default value is frequency.</td>
</tr>
<tr class="even">
<td align="left"><strong>groupColors</strong></td>
<td align="left">Color of groups. groupColors should have the same length as groups.</td>
</tr>
<tr class="odd">
<td align="left"><strong>brewerPalette</strong></td>
<td align="left">This can be also used to indicate group colors. In this case the parameter groupColors should be NULL. e.g: brewerPalette=“Paired”.</td>
</tr>
<tr class="even">
<td align="left"><strong>….</strong></td>
<td align="left">Other arguments passed on to ggplot2.customize custom function or to geom_histogram and geom_density functions from ggplot2 package.</td>
</tr>
</tbody>
</table>
<p><span class="warning">The other arguments which can be used are described at this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2 customize</a>. They are used to customize the plot (axis, title, background, color, legend, ….) generated <strong>using ggplot2</strong> or <strong>easyGgplot2</strong> R package.</span></p>
</div>
<div id="examples" class="section level2">
<h2>Examples</h2>
<pre class="r"><code>library(easyGgplot2)
#plot
plot<-ggplot2.histogram(data=weight, xName=&amp;#39;weight&amp;#39;,groupName=&amp;#39;sex&amp;#39;,
                  groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;))
plot<-ggplot2.customize(plot, 
            mainTitle="Plot of weight histogram \nper sex",
            xtitle="Weight (Kg)", ytitle="Histogram")
print(plot)</code></pre>
</div>
</div>
<div id="easy-ggplot2-ebook" class="section level1">
<h1>Easy ggplot2 ebook</h1>
<p><span class="success">Note that an eBook is available on <strong>easyGgplot2</strong> package <a href="https://www.sthda.com/english/english/download/download-4+easy-ggplot2-book.php">here</a>.</span></p>
<div class="block">
<p>By Alboukadel Kassambara</p>
<p>Copyright 2014 Alboukadel Kassambara. All rights reserved.</p>
<p>Published by STHDA (<a href="https://www.sthda.com/english">https://www.sthda.com/english</a>).</p>
<p>September 2014 : First edition.</p>
<p><strong>Licence</strong> : This document is under creative commons licence (<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">http://creativecommons.org/licenses/by-nc-sa/3.0/</a>).</p>
<p><strong>Contact</strong> : Alboukadel Kassambara <a href="mailto:alboukadel.kassambara@gmail.com">alboukadel.kassambara@gmail.com</a></p>
</div>
<p><br/></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning">This analysis was performed using R (ver. 3.1.0), easyGgplot2 (ver 1.0.0) and ggplot2 (ver 1.0.0).</span></p>
<ul>
<li><a href="http://docs.ggplot2.org/current/">ggplot2 online documentation</a></li>
<li><a href="http://www.cookbook-r.com/Graphs/">Cookbook for R</a></li>
</ul>
</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 Feb 2015 20:54:13 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[ggplot2.customize : How to personalize easily ggplot2 graphs in R statistical software]]></title>
			<link>https://www.sthda.com/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software</link>
			<guid>https://www.sthda.com/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#install-and-load-easyggplot2-package">Install and load easyGgplot2 package</a></li>
<li><a href="#data-format">Data format</a></li>
<li><a href="#basic-box-plot">Basic box plot</a></li>
<li><a href="#customize-your-box-plot">Customize your box plot</a><ul>
<li><a href="#parameters">Parameters</a></li>
<li><a href="#main-title-and-axis-labels">Main title and axis labels</a></li>
<li><a href="#axis-ticks">Axis ticks</a></li>
<li><a href="#background-and-colors">Background and colors</a><ul>
<li><a href="#change-box-plot-background-and-fill-colors">Change box plot background and fill colors</a></li>
</ul></li>
<li><a href="#legend">Legend</a><ul>
<li><a href="#legend-position">Legend position</a></li>
<li><a href="#legend-background-color-title-and-text-font-styles">Legend background color, title and text font styles</a></li>
<li><a href="#change-the-order-of-items-in-the-legend-remove-plot-legend">Change the order of items in the legend, remove plot legend</a></li>
</ul></li>
<li><a href="#axis-scales">Axis scales</a></li>
<li><a href="#create-a-customized-plots-with-few-r-code">Create a customized plots with few R code</a></li>
</ul></li>
<li><a href="#facet-split-a-plot-into-a-matrix-of-panels">Facet : split a plot into a matrix of panels</a><ul>
<li><a href="#facet-with-one-variable">Facet with one variable</a></li>
<li><a href="#facet-with-two-variables">Facet with two variables</a></li>
<li><a href="#facet-scales">Facet scales</a></li>
<li><a href="#facet-label-apperance">Facet label apperance</a></li>
</ul></li>
<li><a href="#ggplot2.customize-function">ggplot2.customize function</a><ul>
<li><a href="#description">Description</a></li>
<li><a href="#usage">usage</a></li>
<li><a href="#arguments">Arguments</a></li>
<li><a href="#examples">Examples</a></li>
</ul></li>
<li><a href="#easy-ggplot2-ebook">Easy ggplot2 ebook</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<div id="introduction" class="section level1">
<h1>Introduction</h1>
<p><strong>ggplot2.customize</strong> is an <strong>easy</strong> to use function, to <strong>customize</strong> <strong>plots</strong> (e.g : <strong>box and whisker plot</strong>, <strong>histogram</strong>, <strong>density plot</strong>, <strong>dotplot</strong>, <strong>scatter plot</strong>, <strong>line plot</strong>, …) generated with <strong>R ggplot2</strong> package. <strong>ggplot2.customize</strong> function is from <strong>easyGgplot2</strong> <strong>R</strong> package and it can be used to personalize graphical parameters including <strong>axis</strong>, <strong>title</strong>, <strong>background</strong>, <strong>color</strong>, <strong>legend</strong> and more. To be able to run the <strong>R script</strong> of this <strong>tutorial</strong>, you have to install <strong>easyGgplot2</strong>. This is explained in the next section.</p>
<p>The aim of this <strong>tutorial</strong> is to show you step by step, how to plot and customize a <strong>box plot</strong> using ggplot2.customize function.</p>
<p><span class="warning">Note that all the <strong>R scripts</strong> used in this <strong>tutorial</strong> to customize <strong>ggplot2 boxplot</strong> can also be applied to personalize the others <strong>graphics</strong> (including boxplot, histogram, density plot, dotplot, etc, …) generated by either <strong>ggplot2</strong> or <strong>easyGgplot2</strong> <strong>R</strong> packages.</span></p>
<p>At the end of this <strong>tutorial</strong> you will be able to draw, with few <strong>R code</strong>, the following <strong>plots</strong> :</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-demo.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="336" /></p>

<p><span class="success">The prototype of <code>ggplot2.customize</code> function is described at the end of this document.</span></p>
</div>
<div id="install-and-load-easyggplot2-package" class="section level1">
<h1>Install and load easyGgplot2 package</h1>
<p><strong>easyGgplot2</strong> R package can be installed as follow :</p>
<pre class="r"><code>install.packages("devtools")
library(devtools)
install_github("easyGgplot2", "kassambara")</code></pre>
<p>Load the package using this R code :</p>
<pre class="r"><code>library(easyGgplot2)</code></pre>
</div>
<div id="data-format" class="section level1">
<h1>Data format</h1>
<p><span class="success">The data must be a numeric vector or a data.frame (columns are variables and rows are observations).</span></p>
<p>ToothGrowth data is used in the following examples.</p>
<pre class="r"><code># data.frame
df <- ToothGrowth
head(df)</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>
<br/>

<div class="block">
<p>ToothGrowth describes the effect of Vitamin C on Tooth growth in Guinea pigs. The response is the length (len) of teeth in each of 10 guinea pigs at each of three dose levels of Vitamin C (0.5, 1, and 2 mg) with each of two delivery methods (orange juice or ascorbic acid).</p>
The data is a data frame with 60 observations on 3 variables.
* [,1] len numeric Tooth length.
* [,2] supp factor Supplement type (VC or OJ).
* [,3] dose numeric Dose in milligrams.

</div>
<p><br/></p>
</div>
<div id="basic-box-plot" class="section level1">
<h1>Basic box plot</h1>
<p>You can generate basic box plot using either <strong>ggplot2.boxplot</strong> [easyGgplot2 package] or <strong>geom_boxplot</strong> [ggplot2 package].</p>
<pre class="r"><code># Boxplot using ggplot2 package
p <- ggplot(ToothGrowth, aes(factor(dose), len))+geom_boxplot()
p

# Boxplot using easyGgplot2 package
p<-ggplot2.boxplot(data = ToothGrowth, xName = &amp;#39;dose&amp;#39;,yName = &amp;#39;len&amp;#39;)
p</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-basic_boxplot1.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-basic_boxplot2.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="163.2" /></p>
</div>
<div id="customize-your-box-plot" class="section level1">
<h1>Customize your box plot</h1>
<div id="parameters" class="section level2">
<h2>Parameters</h2>
<p>The arguments that can be used to customize x and y axis are listed below :</p>
<table>
<thead>
<tr class="header">
<th align="left">Parameters</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>xShowTitle, yShowTitle</strong></td>
<td align="left">if TRUE, x and y axis titles will be shown. Set the value to FALSE to hide axis labels. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtitle, ytitle</strong></td>
<td align="left">x and y axis labels. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xtitleFont, ytitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis titles. Possible values for the <strong>style</strong>:“plain”, “italic”, “bold”, “bold.italic”. Color can be specified as an hexadecimal code (e.g: “#FFCC00”) or by the name (e.g : “red”, “green”). Default values are <code>xtitleFont = c(14,"bold", "black"), ytitleFont = c(14,"bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xlim, ylim</strong></td>
<td align="left">limit for the x and y axis. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xScale, yScale</strong></td>
<td align="left">x and y axis scales. Possible values : c(“none”, “log2”, “log10”). e.g: yScale = “log2”. Default values are <code>NULL</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xShowTickLabel, yShowTickLabel</strong></td>
<td align="left">if TRUE, x and y axis tick mark labels will be shown. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xTickLabelFont, yTickLabelFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis tick label fonts. Default value are <code>xTickLabelFont = c(12, "bold", "black"), yTickLabelFont = c(12, "bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtickLabelRotation, ytickLabelRotation</strong></td>
<td align="left">Rotation angle of x and y axis tick labels. Default value are <code>0</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>hideAxisTicks</strong></td>
<td align="left">if TRUE, x and y axis ticks are hidden. Default value is <code>FALSE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>axisLine</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the line type and the color of axis lines. Default value is <code>c(0.5, "solid", "#E5E5E5")</code>.</td>
</tr>
</tbody>
</table>
</div>
<div id="main-title-and-axis-labels" class="section level2">
<h2>Main title and axis labels</h2>
<pre class="r"><code># Change main title and axis titles
ggplot2.customize(p,
                mainTitle = "Plot of length \n by dose",
                xtitle = "Dose (mg)", ytitle = "Length")

# Customize title styles. Possible values for the font style :
  # &amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.customize(p,
                xtitle = "Dose (mg)", ytitle = "Length",
                mainTitle = "Plot of length \n by dose",
                mainTitleFont = c(14,"bold.italic", "red"),
                xtitleFont = c(14,"bold", "#993333"), ytitleFont = c(14,"bold", "#993333"))

# Hide x an y axis titles
ggplot2.customize(p, xShowTitle = FALSE, yShowTitle = FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-title1.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-title2.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-title3.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="163.2" /></p>
</div>
<div id="axis-ticks" class="section level2">
<h2>Axis ticks</h2>
<pre class="r"><code># Axis ticks labels and orientaion
ggplot2.customize(p,
                xShowTitle = FALSE, yShowTitle = FALSE,
                xTickLabelFont = c(14,"bold", "#993333"),
                yTickLabelFont = c(14,"bold", "#993333"),
                xtickLabelRotation = 45, ytickLabelRotation = 45)

# Hide axis tick labels
ggplot2.customize(p,
                xShowTitle = FALSE, yShowTitle = FALSE,
                xShowTickLabel = FALSE, yShowTickLabel = FALSE)

# Hide axis ticks
ggplot2.customize(p,
                xShowTitle = FALSE, yShowTitle = FALSE,
                xShowTickLabel = FALSE, yShowTickLabel = FALSE,
                hideAxisTicks = TRUE)

# AxisLine : a vector of length 3 indicating the size,
  #the line type and the color of axis lines
ggplot2.customize(p, axisLine = c(1, "solid", "darkblue"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-axis-ticks1.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-axis-ticks2.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-axis-ticks3.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-axis-ticks4.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="163.2" /></p>
</div>
<div id="background-and-colors" class="section level2">
<h2>Background and colors</h2>
<div id="change-box-plot-background-and-fill-colors" class="section level3">
<h3>Change box plot background and fill colors</h3>
<pre class="r"><code># change background color to "white". Default is "gray"
ggplot2.customize(p,backgroundColor = "white")

# change background color to "lightblue" and grid color to "white"
ggplot2.customize(p, backgroundColor = "lightblue",
                  gridColor = "white")
             
# remove grid; remove top and right borders around the plot;
# change  axis lines
ggplot2.customize(p,
                backgroundColor = "white",
                removePanelGrid = TRUE,removePanelBorder = TRUE,
                axisLine = c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-background-color1.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-background-color2.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-background-color3.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="163.2" /></p>
<p><span class = "warning">Colors can be specified as a hexadecimal RGB triplet, such as <code>"#FFCC00"</code> or by names (e.g : <code>"red"</code> ). You can also use other color scales, such as ones taken from the RColorBrewer package. The different <a href="https://www.sthda.com/english/english/wiki/colors-in-r">color systems</a> available in R have been described in detail <a href="https://www.sthda.com/english/english/wiki/colors-in-r">here</a>.<span></p>
</div>
</div>
<div id="legend" class="section level2">
<h2>Legend</h2>
<div id="legend-position" class="section level3">
<h3>Legend position</h3>
<pre class="r"><code># Color the box plot accoording to the groupName "dose"
# Create legend
p1<- ggplot2.boxplot(data = ToothGrowth, 
          xName = "dose", yName = "len", groupName = "dose")
p1

# Change the legend position to "top" 
  # Possible values: "left","top", "right", "bottom"
ggplot2.customize(p1, legendPosition = "top")
                
# legendPosition can be also a numeric vector c(x, y)
ggplot2.customize(p1, legendPosition = c(0.8,0.2))           </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-legend-position1.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-legend-position2.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-legend-position3.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /></p>
<p><span class="warning">It is also possible to position the legend inside the plotting area. You have to indicate the x, y coordinates of legend box. x and y values must be between 0 and 1. c(0,0) corresponds to <strong>“bottom left”</strong> and c(1,1) corresponds to <strong>“top right”</strong> position.</span></p>
</div>
<div id="legend-background-color-title-and-text-font-styles" class="section level3">
<h3>Legend background color, title and text font styles</h3>
<pre class="r"><code># Change legend background color, title and text font styles
ggplot2.customize(p1, 
        #legendTitleFont = c(size, style, color)
        legendTitle = "Dose (mg)",
        legendTitleFont = c(10, "bold", "blue"),
        #legendTextFont = c(size, style, color)
        legendTextFont = c(10, "bold.italic", "red"),
        #legendBackground: c(fill, lineSize, lineType, lineColor)
        legendBackground = c("lightblue", 0.5, "solid", "darkblue" )
        )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-legend-background-and-title.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="288" /></p>
</div>
<div id="change-the-order-of-items-in-the-legend-remove-plot-legend" class="section level3">
<h3>Change the order of items in the legend, remove plot legend</h3>
<pre class="r"><code># Change the order of items in the legend
 # legendItemOrder : character vector indicating 
# the order of items in the legends.
ggplot2.customize(p1, legendItemOrder = c("2", "1", "0.5"))

# Remove plot legend
ggplot2.customize(p1, showLegend = FALSE)               </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-legend-item-order1.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-legend-item-order2.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /></p>
</div>
</div>
<div id="axis-scales" class="section level2">
<h2>Axis scales</h2>
<p>Possible values for y axis scale are “none”, “log2” and log10. Default value is “none”.</p>
<pre class="r"><code># Change y axis limit
ggplot2.customize(p1, ylim = c(0,50))
                
# y Log scale. yScale = "log2". 
  # Possible value = "none", "log2" and "log10"
ggplot2.customize(p1,  yScale = "log2")            </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-axis-scale1.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-axis-scale2.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /></p>
</div>
<div id="create-a-customized-plots-with-few-r-code" class="section level2">
<h2>Create a customized plots with few R code</h2>
<pre class="r"><code># Customized box plot with centered dot plot
ggplot2.customize(p1, showLegend = FALSE,
        backgroundColor = "white",
        xtitle = "Dose (mg)", ytitle = "length", 
        mainTitle = "Plot of length \n by dose")

# Remove grid; Remove Top and right border around the plot
ggplot2.customize(p1, showLegend = FALSE,
        backgroundColor = "white",
        xtitle = "Dose (mg)", ytitle = "length", 
        mainTitle = "Plot of length \n by dose",
        removePanelGrid = TRUE,removePanelBorder = TRUE,
        axisLine = c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-customized-plot1.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-customized-plot2.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /></p>
</div>
</div>
<div id="facet-split-a-plot-into-a-matrix-of-panels" class="section level1">
<h1>Facet : split a plot into a matrix of panels</h1>
<p>The approach of <strong>facet</strong> <strong>splits a plot</strong> into a matrix of panels. Each panel displays a different subset of the data.</p>
<div id="facet-with-one-variable" class="section level2">
<h2>Facet with one variable</h2>
<pre class="r"><code># Box plot with multiples groups
p2<- ggplot2.boxplot(data = ToothGrowth,
          xName = "dose", yName = "len", groupName = "supp")
p2

# Facet according to the supp variable
ggplot2.customize(p2, legendPosition = "top",
        faceting = TRUE, facetingVarNames = "supp") 

# Change the direction. Possible values are
  # "vertical", horizontal". default is vertical.
ggplot2.customize(p2, legendPosition = "top",
        faceting = TRUE, facetingVarNames = "supp",
        facetingDirection = "horizontal") </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-facet-with-one-variable1.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-facet-with-one-variable2.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-facet-with-one-variable3.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /></p>
</div>
<div id="facet-with-two-variables" class="section level2">
<h2>Facet with two variables</h2>
<pre class="r"><code># Facet by two variables: dose and supp.
# Rows are dose and columns are supp
ggplot2.customize(p2, legendPosition = "top",
        faceting = TRUE, facetingVarNames = c("dose","supp"))

#Facet by two variables: reverse the order of the 2 variables
#Rows are supp and columns are dose
ggplot2.customize(p2, legendPosition = "top",
        faceting = TRUE, facetingVarNames = c("supp", "dose"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-facet-with-two-variables1.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-facet-with-two-variables2.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /></p>
</div>
<div id="facet-scales" class="section level2">
<h2>Facet scales</h2>
<p>By default, all the panels have the same scale (<code>facetingScales="fixed"</code>). They can be made independent, by setting scales to <code>free</code>, <code>free_x</code>, or <code>free_y</code>.</p>
<pre class="r"><code># Facet with free scales
ggplot2.customize(p2, legendPosition = "top",
        faceting = TRUE, facetingVarNames = c("dose", "supp"),
        facetingScales = "free")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-facet-free-scale.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /></p>
<p><span class="warning">y axis have different scales now in the different panels.</span></p>
</div>
<div id="facet-label-apperance" class="section level2">
<h2>Facet label apperance</h2>
<pre class="r"><code># Change facet text font. Possible values for the font style:
  #&amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.customize(p2, legendPosition = "top",
          faceting = TRUE, facetingVarNames = c("dose","supp"),
          facetingFont = c(12, &amp;#39;bold.italic&amp;#39;, "red"))

#Change the apperance of the rectangle around facet label
ggplot2.customize(p2, legendPosition = "top",
      faceting = TRUE, facetingVarNames = c("dose","supp"),
      facetingRect = list(background = "white", lineType = "solid", 
                        lineColor = "black", lineSize = 1.5)
        )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-facet-label-apperance1.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-customize-facet-label-apperance2.png" title="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" alt="ggplot2 boxplot : ggplot2 tutorial on how to use ggplot2.customize function to personalize easily graphics (main title, axis labels, legend, background and color) generated by ggplot2 using r statistical software" width="240" /></p>
</div>
</div>
<div id="ggplot2.customize-function" class="section level1">
<h1>ggplot2.customize function</h1>
<div id="description" class="section level2">
<h2>Description</h2>
<p>Customize easily a plot generated with either <strong>easyGgplot2</strong> or <strong>ggplot2</strong> <strong>R</strong> packages.</p>
</div>
<div id="usage" class="section level2">
<h2>usage</h2>
<pre class="r"><code>ggplot2.boxplot(plot,...)</code></pre>
</div>
<div id="arguments" class="section level2">
<h2>Arguments</h2>
<p><strong>plot</strong> : A plot object generated with <strong>ggplot2</strong> or <strong>easyGgplot2</strong> package (<strong>boxplot</strong>, <strong>density plot</strong>, <strong>histogram</strong>, <strong>dotplot</strong>, etc ….)</p>
<p><strong>…</strong> : Any argument from the list of the arguments indicated below.</p>
<p><span class = "warning"> The other arguments which can be used are shown in the table below. They are used to customize the plot (<strong>axis</strong>, <strong>title</strong>,** background<strong>, </strong>color<strong>, </strong>legend**, ….) generated by easyGgplot2 and ggplot2.</span></p>
<table>
  <tr><th>
Arguments
</th><th>
Descriptions
</th> </tr>
  
<tr><td colspan=2 style="background-color:#336699; color:white;">
Customize plot title
</td></tr>
  <tr><td>
<b>mainTitle</b>
</td><td>
Title of the plot.
</td></tr>
  <tr><td>
<b>mainTitleFont</b>
</td><td>
A vector of length 3 indicating respectively the size, the style and the color of main title. Possible values for font style are “plain”, “italic”, “bold”, “bold.italic”. Color can be specified as an hexadecimal code (e.g: “#FFCC00”) or by the name (e.g : “red”, “green”). <b/>Default value is: mainTitleFont=c(14, “bold”, “black”).</b>
</td></tr>
  
<tr><td colspan=2 style = "background-color:#336699; color:white;">
Customize x and y axis
</td></tr>
  <tr><td>
<b>xShowTitle, yShowTitle</b>
</td><td>
if TRUE, x axis and y axis titles will be shown. <b>Default values are TRUE.</b>
</td></tr>
  <tr><td>
<b>xtitle, ytitle</b>
</td><td>
x and y axis labels.
</td></tr>
  <tr><td>
<b>xtitleFont, ytitleFont</b>
</td><td>
A vector of length 3 indicating respectively the size, the style and the color of x and y axis titles. <b>Default values are c(14,“bold”, “black”).</b>
</td></tr>
  <tr><td>
<b>xlim, ylim</b>
</td><td>
Limit for the x and y axis. <b>Default values are NULL</b>.
</td></tr>
  <tr><td>
<b>xScale, yScale</b>
</td><td>
x and y axis scales. Possible values are c(“none”, “log2”, “log10”). Example: yScale = “log2”. <b>Default values are “none”.</b>
</td></tr>
  <tr><td>
<b>xShowTickLabel, yShowTickLabel</b>
</td><td>
if TRUE, x and y axis tick mark labels will be shown. <b>Default values are TRUE.</b>
</td></tr>
  <tr><td>
<b>xTickLabelFont, yTickLabelFont</b>
</td><td>
A vector of length 3 indicating respectively the size, the style and the color of x and y axis tick label fonts. <b>Default values are c(12, “bold”, “black”).</b>
</td></tr>
  <tr><td>
<b>xtickLabelRotation, ytickLabelRotation</b>
</td><td>
Rotation angle of x and y axis tick labels. <b>Default values are 0</b>.
</td></tr>
  <tr><td>
<b>hideAxisTicks</b>
</td><td>
if TRUE, x and y axis ticks are removed. <b>Default value is FALSE</b>.
</td></tr>
  <tr><td>
<b>axisLine</b>
</td><td>
A vector of length 3 indicating respectively the size, the line type and the color of axis lines.<b> Default value is c(0.5, “solid”, “#E5E5E5”).</b>
</td></tr>
  
<tr><td colspan = 2 style = "background-color:#336699; color:white;">
Customize plot background
</td></tr>
  <tr><td>
<b>removePanelBorder</b>
</td><td>
if TRUE, the top-right border of the plot are removed. <b>Default value is FALSE.</b>
</td></tr>
  <tr><td>
<b>removePanelGrid</b>
</td><td>
if TRUE, panel grids are removed. <b>Default value is FALSE.</b>
</td></tr>
  <tr><td>
<b>backgroundColor</b>
</td><td>
background color of plot panel. <b>Default value is “gray”.</b>
</td></tr>
  <tr><td>
<b>gridColor</b>
</td><td>
Color of plot panel grids. <b>Default value is “white”.</b>
</td></tr>
  
<tr><td colspan = 2 style = "background-color:#336699; color:white;">
Customize plot legend
</td></tr>
  <tr><td>
<b>showLegend</b>
</td><td>
if TRUE, plot legend will be shown. <b>Default value is TRUE</b>.
</td></tr>
  <tr><td>
<b>legendPosition</b>
</td><td>
Position of legend box. <b>Default value is “right”</b>. Possible values for legend position are “right”, “left”,“top”, “bottom”. LegendPosition can be also a numeric vector c(x, y) indicating the coordinate of legend box. x and y values must be between 0 and 1. c(0,0) corresponds to the “bottom left” and c(1,1) corresponds to the “top right” position.
</td></tr>
  <tr><td>
<b>legendBackground</b>
</td><td>
A vector of length 4 indicating boxFill, boxLineSize, boxLineType, boxLineColor. <b>Default value is legendBackground = c(“#FFFFFF”, 0.5, “blank”, “black” ).</b>
</td></tr>
  <tr><td>
<b>legendTextFont</b>
</td><td>
A vector of length 3 indicating respectively the size, the style and the color of legend text. <b>Default value is c(10, “plain”, “black”)</b>. Possible values for font style are “plain”, “italic”, “bold”, “bold.italic”.
</td></tr>
  <tr><td>
<b>legendTitleFont</b>
</td><td>
A vector of length 3 indicating respectively the size, the style and the color of legend title. <b>Default value is c(10, “plain”, “black”)</b>
</td></tr>
  <tr><td>
<b>legendItemOrder</b>
</td><td>
Character vector indicating the order of items in the legends. Example: c(“2”, “1”, “0.5”)
</td></tr>
  
<tr><td colspan = 2 style = "background-color:#336699; color:white;">
Faceting : split a plot into a matrix of panels
</td></tr>
  <tr><td>
<b>faceting</b>
</td><td>
if TRUE, the data are split up by one or two variables and graphs are displayed in different panels. In this case, you have to indicate the facetingVarNames. <b>Default value is FALSE</b>.
</td></tr>
   <tr><td>
<b>facetingVarNames</b>
</td><td>
the names of the columns containing variables to use for faceting. <b>Default value is NULL</b>.
</td></tr>
   <tr><td>
<b>facetingDirection</b>
</td><td>
possibles values are “vertical” and “horizontal”. Default value is vertical. <b>Default value is “vertical”</b>.
</td></tr>
<tr><td>
<b>facetingScales</b>
</td><td> 
By default, all the panels have the same scale (<code>facetingScales = "fixed"</code>). They can be made independent, by setting scales to “free”, “free_x”, or “free_y”. <b>Default value is “fixed”</b>.
</td></tr>
<tr><td>
<b>facetingFont</b>
</td><td>
Change facet label appearance. A vector of length 3 indicating respectively the size, the font style and the color of the text. <b>Default value is facetingFont = c(size = 12, font = “plain”, color = “black”).</b>
</td></tr>
<tr><td>
<b>facetingRect</b>
</td><td>
Modify the appearance of the rectangle around the facet label.<b>Default value is <span class="blue">list</span>(background = NULL, lineType = NULL, lineColor = NULL, lineSize = NULL).</b>
</td></tr>
<tr><td>
<b>facetingTextAngles</b>
</td><td>
Modify the facet label text orientation. It indicates the angles of the x and y texts (in [0, 360]). <b>Default value is c(NULL, NULL).</b>
</td></tr>

<tr><td colspan = 2 style = "background-color:#336699; color:white;">
Others
</td></tr>
  <tr><td>
<b>orientation</b>
</td><td>
Change the orientation of the plot. Possible values are c(“standard”, “horizontal”, “yAxisReversed”). <b>Default value is “standard”</b>.
</td></tr> 
</table>
      

<p><span class="success">Possible values for font style are “plain”, “italic”, “bold”, “bold.italic”. </span></p>
</div>
<div id="examples" class="section level2">
<h2>Examples</h2>
<pre class="r"><code>plot<-ggplot2.boxplot(data = ToothGrowth, 
              xName = &amp;#39;dose&amp;#39;, yName = &amp;#39;len&amp;#39;)
plot<-ggplot2.customize(plot, mainTitle = "Plot of length \n by dose",
            xtitle = "Dose (mg)", ytitle = "Length")
print(plot)</code></pre>
<p><br/></p>
</div>
</div>
<div id="easy-ggplot2-ebook" class="section level1">
<h1>Easy ggplot2 ebook</h1>
<p><span class="success">Note that an eBook is available on <strong>easyGgplot2</strong> package <a href="https://www.sthda.com/english/english/download/download-4+easy-ggplot2-book.php">here</a>.</span></p>
<div class="block">
<p>By Alboukadel Kassambara</p>
<p>Copyright 2014 Alboukadel Kassambara. All rights reserved.</p>
<p>Published by STHDA (<a href="https://www.sthda.com/english">https://www.sthda.com/english</a>).</p>
<p>September 2014 : First edition.</p>
<p><strong>Licence</strong> : This document is under creative commons licence (<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">http://creativecommons.org/licenses/by-nc-sa/3.0/</a>).</p>
<p><strong>Contact</strong> : Alboukadel Kassambara <a href="mailto:alboukadel.kassambara@gmail.com">alboukadel.kassambara@gmail.com</a></p>
</div>
<p><br/></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning">This analysis was performed using R (ver. 3.1.0), easyGgplot2 (ver 1.0.0) and ggplot2 (ver 1.0.0).</span></p>
<ul>
<li><a href="http://docs.ggplot2.org/current/">ggplot2 online documentation</a></li>
<li><a href="http://www.cookbook-r.com/Graphs/">Cookbook for R</a></li>
</ul>
</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 Feb 2015 20:52:12 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[ggplot2 density : Easy density plot using ggplot2 and R statistical software]]></title>
			<link>https://www.sthda.com/english/wiki/ggplot2-density-easy-density-plot-using-ggplot2-and-r-statistical-software</link>
			<guid>https://www.sthda.com/english/wiki/ggplot2-density-easy-density-plot-using-ggplot2-and-r-statistical-software</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#install-and-load-easyggplot2-package">Install and load easyGgplot2 package</a></li>
<li><a href="#data-format">Data format</a></li>
<li><a href="#basic-density-plot">Basic density plot</a></li>
<li><a href="#change-the-line-type-of-the-density-plot">Change the line type of the density plot</a></li>
<li><a href="#density-plot-with-multiple-groups">Density plot with multiple groups</a><ul>
<li><a href="#customize-your-density-plot">Customize your density plot</a></li>
</ul></li>
<li><a href="#parameters">Parameters</a><ul>
<li><a href="#main-title-and-axis-labels">Main title and axis labels</a><ul>
<li><a href="#axis-ticks">Axis ticks</a></li>
</ul></li>
<li><a href="#background-and-colors">Background and colors</a><ul>
<li><a href="#change-density-plot-background-and-fill-colors">Change density plot background and fill colors</a></li>
<li><a href="#change-density-plot-color-according-to-the-group">Change density plot color according to the group</a></li>
</ul></li>
<li><a href="#legend">Legend</a><ul>
<li><a href="#legend-position">Legend position</a></li>
<li><a href="#legend-background-color-title-and-text-font-styles">Legend background color, title and text font styles</a></li>
</ul></li>
<li><a href="#axis-scales">Axis scales</a></li>
<li><a href="#create-a-customized-plots-with-few-r-code">Create a customized plots with few R code</a></li>
</ul></li>
<li><a href="#facet-split-a-plot-into-a-matrix-of-pannels">Facet : split a plot into a matrix of pannels</a><ul>
<li><a href="#facet-with-one-variable">Facet with one variable</a></li>
<li><a href="#faceting-with-two-variables">Faceting with two variables</a></li>
<li><a href="#facet-scales">Facet scales</a></li>
<li><a href="#facet-label-apperance">Facet label apperance</a></li>
</ul></li>
<li><a href="#ggplot2.density-function">ggplot2.density function</a><ul>
<li><a href="#description">Description</a></li>
<li><a href="#usage">usage</a></li>
<li><a href="#arguments">Arguments</a></li>
<li><a href="#examples">Examples</a></li>
</ul></li>
<li><a href="#easy-ggplot2-ebook">Easy ggplot2 ebook</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<div id="introduction" class="section level1">
<h1>Introduction</h1>
<p><strong>ggplot2.density</strong> is an easy to use function for plotting <strong>density curve</strong> using <strong>ggplot2</strong> package and <strong>R statistical software</strong>. The aim of this <strong>ggplot2 tutorial</strong> is to show you step by step, how to make and customize a <strong>density plot</strong> using ggplot2.density function. This function can also be used to personalize the different graphical parameters including <strong>main title</strong>, <strong>axis labels</strong>, <strong>legend</strong>, <strong>background</strong> and <strong>colors</strong>.</p>
<p>ggplot2.density function is from <a href="https://www.sthda.com/english/english/wiki/easyggplot2"><strong>easyGgplot2</strong></a> R package. An R script is available in the next section to install the package.</p>
<p>At the end of this tutorial you will be able to draw, with few R code, the following plots:</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-demo1.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-demo2.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /></p>

<p><span class="warning"><strong>ggplot2.density</strong> function is described in detail at the end of this document.</span></p>
</div>
<div id="install-and-load-easyggplot2-package" class="section level1">
<h1>Install and load easyGgplot2 package</h1>
<p><strong>easyGgplot2</strong> R package can be installed as follow :</p>
<pre class="r"><code>install.packages("devtools")
library(devtools)
install_github("easyGgplot2", "kassambara")</code></pre>
<p>Load the package using this R code :</p>
<pre class="r"><code>library(easyGgplot2)</code></pre>
</div>
<div id="data-format" class="section level1">
<h1>Data format</h1>
<p><span class="success">The data must be a numeric vector or a data.frame (columns are variables and rows are observations).</span></p>
<p>weight data, from <strong>easyGgplot2</strong> package, will be used in the following examples.</p>
<pre class="r"><code># create a numeric vector
numVector<-rnorm(100)
head(numVector)</code></pre>
<pre><code>## [1] -0.8557 -0.6604  0.1977  2.0698 -1.1753 -0.5429</code></pre>
<pre class="r"><code># data.frame
head(weight)</code></pre>
<pre><code>##      sex weight
## 1 Female  63.79
## 2 Female  65.28
## 3 Female  66.08
## 4 Female  62.65
## 5 Female  65.43
## 6 Female  65.51</code></pre>
<br/>

<div class="block">
weight data contain the weight of 400 people (200 females and 200 males).
</div>
<p><br/></p>
</div>
<div id="basic-density-plot" class="section level1">
<h1>Basic density plot</h1>
<pre class="r"><code># Density of a single numeric vector 
#ggplot2.density(data=numVector)

# Basic density plot from the vector "weight"
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;)

# Add mean line to the density plot
# Change the density line color, linetype and line size
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
        addMeanLine=TRUE, meanLineColor="red",
        meanLineType="dashed", meanLineSize=1,
        colour="darkblue", linetype="dotted", size=1.5)

#Change the orientation: Horizontal density plot
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
          orientation="horizontal")

# y Axis reversed
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
        orientation="yAxisReversed")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-basic-density1.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-basic-density2.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-basic-density3.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-basic-density4.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /></p>
</div>
<div id="change-the-line-type-of-the-density-plot" class="section level1">
<h1>Change the line type of the density plot</h1>
<p><span class="warning">Different <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">point shapes</a> and <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">line types</a> can be used in the plot. By default, ggplot2 uses solid line type and circle shape.</span></p>
<ul>
<li>The different <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">point shapes</a> in R are described <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">here</a>.</li>
<li>The available <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">line types</a> are shown <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">here</a>.</li>
</ul>
<pre class="r"><code># Change the density line color and line type
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,linetype="longdash")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-line-type.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /></p>
</div>
<div id="density-plot-with-multiple-groups" class="section level1">
<h1>Density plot with multiple groups</h1>
<pre class="r"><code># Multiple density curves on the same plot
# Color the density plot accoording to the groupName "grp"
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
                legendPosition="top")

# Density plots with semi-transparent fill.
# alpha is the transparency of the overlaid color
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
    legendPosition="top",
    alpha=0.5, fillGroupDensity=TRUE )

# Density plots with mean lines
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
                legendPosition="top",
                addMeanLine=TRUE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-multiple-groups1.png" title="Density with multiple groups" alt="Density with multiple groups" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-multiple-groups2.png" title="Density with multiple groups" alt="Density with multiple groups" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-multiple-groups3.png" title="Density with multiple groups" alt="Density with multiple groups" width="240" /></p>
<div id="customize-your-density-plot" class="section level2">
<h2>Customize your density plot</h2>
</div>
</div>
<div id="parameters" class="section level1">
<h1>Parameters</h1>
<p>The arguments that can be used to customize titles and x and y axis are listed below :</p>
<table>
<thead>
<tr class="header">
<th align="left">Parameters</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>mainTitle</strong></td>
<td align="left">the title of the plot</td>
</tr>
<tr class="even">
<td align="left"><strong>mainTitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style (“italic”, “bold”, “bold.italic”) and the color of x and y axis titles. <code>Default value is: mainTitleFont=c(14, "bold", "black")</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xShowTitle, yShowTitle</strong></td>
<td align="left">if TRUE, x and y axis titles will be shown. Set the value to FALSE to hide axis labels. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtitle, ytitle</strong></td>
<td align="left">x and y axis labels. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xtitleFont, ytitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis titles. Possible values for the <strong>style</strong>:“plain”, “italic”, “bold”, “bold.italic”. <strong>Color</strong> can be specified as an hexadecimal code (e.g: “#FFCC00”) or by the name (e.g : “red”, “green”). Default values are <code>xtitleFont=c(14,"bold", "black"), ytitleFont=c(14,"bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xlim, ylim</strong></td>
<td align="left">limit for the x and y axis. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xScale, yScale</strong></td>
<td align="left">x and y axis scales. Possible values : c(“none”, “log2”, “log10”). e.g: yScale=“log2”. Default values are <code>NULL</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xShowTickLabel, yShowTickLabel</strong></td>
<td align="left">if TRUE, x and y axis tick mark labels will be shown. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xTickLabelFont, yTickLabelFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis tick label fonts. Default value are <code>xTickLabelFont=c(12, "bold", "black"), yTickLabelFont=c(12, "bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtickLabelRotation, ytickLabelRotation</strong></td>
<td align="left">Rotation angle of x and y axis tick labels. Default value are <code>0</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>hideAxisTicks</strong></td>
<td align="left">if TRUE, x and y axis ticks are hidden. Default value is <code>FALSE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>axisLine</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the line type and the color of axis lines. Default value is <code>c(0.5, "solid", "#E5E5E5")</code>.</td>
</tr>
</tbody>
</table>
<p>For more details follow this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2.customize</a>.</p>
<div id="main-title-and-axis-labels" class="section level2">
<h2>Main title and axis labels</h2>
<pre class="r"><code># Change main title and axis titles
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
        mainTitle="Density curve",
        xtitle="Weight (kg)", ytitle="Density")

# Customize title styles. Possible values for the font style :
  # &amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
        xtitle="Weight (kg)", ytitle="Density",
        mainTitle="Density curve",
        mainTitleFont=c(14,"bold.italic", "red"),
        xtitleFont=c(14,"bold", "#993333"),
        ytitleFont=c(14,"bold", "#993333"))

# Hide x an y axis titles
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
         xShowTitle=FALSE, yShowTitle=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-main-title-and-axis-labels1.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-main-title-and-axis-labels2.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-main-title-and-axis-labels3.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="163.2" /></p>
<div id="axis-ticks" class="section level3">
<h3>Axis ticks</h3>
<pre class="r"><code># Axis ticks labels and orientaion
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
        xShowTitle=FALSE, yShowTitle=FALSE,
        xTickLabelFont=c(14,"bold", "#993333"),
        yTickLabelFont=c(14,"bold", "#993333"),
        xtickLabelRotation=45, ytickLabelRotation=45)

# Hide axis tick labels
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
        xShowTitle=FALSE, yShowTitle=FALSE,
        xShowTickLabel=FALSE, yShowTickLabel=FALSE)

# Hide axis ticks
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
        xShowTitle=FALSE, yShowTitle=FALSE,
        xShowTickLabel=FALSE,
        yShowTickLabel=FALSE,hideAxisTicks=TRUE)

# AxisLine : a vector of length 3 indicating the size,
  #the line type and the color of axis lines
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
      axisLine=c(1, "solid", "darkblue"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-axis-ticks1.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-axis-ticks2.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-axis-ticks3.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-axis-ticks4.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="163.2" /></p>
</div>
</div>
<div id="background-and-colors" class="section level2">
<h2>Background and colors</h2>
<div id="change-density-plot-background-and-fill-colors" class="section level3">
<h3>Change density plot background and fill colors</h3>
<pre class="r"><code># Change background color to "white". Default is "gray"
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
        backgroundColor="white")

# Change background color to "lightblue" and grid color to "white"
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
        backgroundColor="lightblue", gridColor="white")

# Change plot fill color
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
         backgroundColor="white", densityFill=&amp;#39;#FFAAD4&amp;#39;)

# Remove grid; remove top and right borders around the plot;
# change  axis lines
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
        backgroundColor="white", densityFill=&amp;#39;#FFAAD4&amp;#39;,
        removePanelGrid=TRUE,removePanelBorder=TRUE,
        axisLine=c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-background-color1.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-background-color2.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-background-color3.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-background-color4.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="163.2" /></p>
</div>
<div id="change-density-plot-color-according-to-the-group" class="section level3">
<h3>Change density plot color according to the group</h3>
<p><span class="warning">Colors can be specified as a hexadecimal RGB triplet, such as <code>"#FFCC00"</code> or by names (e.g : <code>"red"</code> ). You can also use other color scales, such as ones taken from the RColorBrewer package. The different <a href="https://www.sthda.com/english/english/wiki/colors-in-r">color systems</a> available in R have been described in detail <a href="https://www.sthda.com/english/english/wiki/colors-in-r">here</a>.<span></p>
<p><span class="success">To change <strong>density plot</strong> color according to the group, you have to specify the name of the data column containing the groups using the argument <code>groupName</code>. Use the argument <code>groupColors</code>, to specify colors by <code>hexadecimal</code> code or by <code>name</code>. In this case, the length of groupColors should be the same as the number of the groups. Use the argument <code>brewerPalette</code>, to specify colors using <code>RColorBrewer</code>palette.</span></p>
<pre class="r"><code># Change group colors using hexadecimal colors
# alpha is the transparency level of overlaid color. 
  #The value can variate from 0 (total transparency) 
  #to 1 (no transparency)
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
                groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;),
                fillGroupDensity=TRUE, alpha=0.5,
                legendPosition="top")

# Change group colors using brewer palette: "Paired"
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
                brewerPalette="Paired",
                fillGroupDensity=TRUE, alpha=0.5,
                legendPosition="top")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-density-color1.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-density-color2.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /></p>
<br/>
<div class="block">
<p>Color can also be changed by using names as follow :</p>
<pre class="r"><code># Change group colors using color names
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
          groupColors=c(&amp;#39;aquamarine3&amp;#39;,&amp;#39;goldenrod1&amp;#39;),
          fillGroupDensity=TRUE, alpha=0.5 )</code></pre>
</div>
<p><br/></p>
</div>
</div>
<div id="legend" class="section level2">
<h2>Legend</h2>
<div id="legend-position" class="section level3">
<h3>Legend position</h3>
<pre class="r"><code># Change the legend position to "top" 
  # (possible values: "left","top", "right", "bottom")
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
                legendPosition="top")

# legendPosition can be also a numeric vector c(x, y)
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
                legendPosition=c(0.8,0.2))

# Remove legend
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
                showLegend=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-legend-position1.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-legend-position2.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-legend-position3.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /></p>
<p><span class="warning">It is also possible to position the legend inside the plotting area. You have to indicate the x, y coordinates of legend box. x and y values must be between 0 and 1. <code>c(0,0)</code> corresponds to <code>"bottom left"</code> and <code>c(1,1)</code> corresponds to <code>"top right"</code> position.</span></p>
</div>
<div id="legend-background-color-title-and-text-font-styles" class="section level3">
<h3>Legend background color, title and text font styles</h3>
<pre class="r"><code># Change legend background color, title and text font styles
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
      # legendTitleFont=c(size, style, color)
      legendTitle="Groups", legendTitleFont=c(10, "bold", "blue"),
      #legendTextFont=c(size, style, color)
      legendTextFont=c(10, "bold.italic", "red"),
      #legendBackground: c(fill, lineSize, lineType, lineColor)
      legendBackground=c("lightblue", 0.5, "solid", "darkblue" )
      )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-legend-background-and-title.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="288" /></p>
</div>
</div>
<div id="axis-scales" class="section level2">
<h2>Axis scales</h2>
<p>Possible values for x axis scale are “none”, “log2” and log10. Default value is “none”.</p>
<pre class="r"><code># Change x axis limit
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
                showLegend=FALSE, xlim=c(60,72))

# x Log scale. Possible values="none", "log2" and "log10"
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
                showLegend=FALSE, xScale="log2")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-axis-scale1.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-axis-scale2.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /></p>
</div>
<div id="create-a-customized-plots-with-few-r-code" class="section level2">
<h2>Create a customized plots with few R code</h2>
<pre class="r"><code>#Customized density
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
      groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;), showLegend=FALSE,
      backgroundColor="white",
      xtitle="Weight (kg)", ytitle="Density", 
      mainTitle="Weight density curve \nper sex",
      addMeanLine=TRUE
      )

#Remove grid; Remove Top and right border around the plot 
#and fill each density curve according to the group
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, groupName=&amp;#39;sex&amp;#39;,
    groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;), showLegend=FALSE,
    backgroundColor="white",
    xtitle="Weight (kg)", ytitle="Density", 
    mainTitle="Weight density curve \nper sex",
    removePanelGrid=TRUE,removePanelBorder=TRUE,
    axisLine=c(0.5, "solid", "black"),
    fillGroupDensity=TRUE, alpha=0.5)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-customized-plot1.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-customized-plot2.png" title="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" alt="r data visualization with ggplot2 density plot  : tutorial on how to use ggplot2.density function to easily make density curve with R statistical software" width="240" /></p>
<p><span class="success">The argument alpha is used to specify the transparency of colors.</span></p>
</div>
</div>
<div id="facet-split-a-plot-into-a-matrix-of-pannels" class="section level1">
<h1>Facet : split a plot into a matrix of pannels</h1>
<p>The facet approach splits a plot into a matrix of panels. Each panel shows a different subset of the data.</p>
<div id="facet-with-one-variable" class="section level2">
<h2>Facet with one variable</h2>
<pre class="r"><code>#Facet according to the sex variable
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,
        groupName=&amp;#39;sex&amp;#39;, legendPosition="top",
        faceting=TRUE, facetingVarNames="sex") 

# Change the direction. possible values are "vertical", horizontal".
# default is vertical.
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;, 
        groupName=&amp;#39;sex&amp;#39;, legendPosition="top",
        faceting=TRUE, facetingVarNames="sex",
        facetingDirection="horizontal") </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-facet-with-one-variable1.png" title="ggplot2 density and facet approch, one variable" alt="ggplot2 density and facet approch, one variable" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-facet-with-one-variable2.png" title="ggplot2 density and facet approch, one variable" alt="ggplot2 density and facet approch, one variable" width="240" /></p>
</div>
<div id="faceting-with-two-variables" class="section level2">
<h2>Faceting with two variables</h2>
<p>The <strong>mtcars</strong> data is used in the following examples.</p>
<pre class="r"><code>data(mtcars)
head(mtcars)</code></pre>
<pre><code>##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1</code></pre>
<p><span class="success"> mtcars (Motor Trend Car Road Tests) comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles.</span></p>
<pre class="r"><code>#Facet by two variables: vs and am.
#Rows are vs and columns are am
ggplot2.density(data=mtcars, xName=&amp;#39;mpg&amp;#39;, groupName=&amp;#39;vs&amp;#39;,
        legendPosition="top",
        faceting=TRUE, facetingVarNames=c("vs", "am"))

# Facet by two variables: reverse the order of the 2 variables
#Rows are am and columns are vs
ggplot2.density(data=mtcars, xName=&amp;#39;mpg&amp;#39;, groupName=&amp;#39;vs&amp;#39;,
        legendPosition="top",
        faceting=TRUE, facetingVarNames=c("am", "vs"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-facet-with-two-variables1.png" title="ggplot2 density plot and facet approch, two variables" alt="ggplot2 density plot and facet approch, two variables" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-facet-with-two-variables2.png" title="ggplot2 density plot and facet approch, two variables" alt="ggplot2 density plot and facet approch, two variables" width="240" /></p>
</div>
<div id="facet-scales" class="section level2">
<h2>Facet scales</h2>
<p>By default, all the panels have the same scale (<code>facetingScales="fixed"</code>). They can be made independent, by setting scales to <code>free</code>, <code>free_x</code>, or <code>free_y</code>.</p>
<pre class="r"><code># Facet with free scales
ggplot2.density(data=mtcars, xName=&amp;#39;mpg&amp;#39;, groupName=&amp;#39;vs&amp;#39;,
      legendPosition="top",
      faceting=TRUE, facetingVarNames=c("vs", "am"),
      facetingScales="free")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-facet-free-scale.png" title="ggplot2 density plot and facet approch, free scale" alt="ggplot2 density plot and facet approch, free scale" width="336" /></p>
<p><span class="success">As you can see in the above plot, y axis have different scales in the different panels.</span></p>
</div>
<div id="facet-label-apperance" class="section level2">
<h2>Facet label apperance</h2>
<pre class="r"><code># Change facet text font. Possible values for the font style:
  #&amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.density(data=mtcars, xName=&amp;#39;mpg&amp;#39;, groupName=&amp;#39;vs&amp;#39;,
        legendPosition="top",
        faceting=TRUE, facetingVarNames=c("vs", "am"),
        facetingFont=c(12, &amp;#39;bold.italic&amp;#39;, "red"))

# Change the apperance of the rectangle around facet label
ggplot2.density(data=mtcars, xName=&amp;#39;mpg&amp;#39;, groupName=&amp;#39;vs&amp;#39;,
      legendPosition="top",
      faceting=TRUE, facetingVarNames=c("vs", "am"),
      facetingRect=list(background="white", lineType="solid",
                      lineColor="black", lineSize=1.5)
      )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-facet-label-apperance1.png" title="ggplot2 density  plot and facet approch, facet label" alt="ggplot2 density  plot and facet approch, facet label" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-density-facet-label-apperance2.png" title="ggplot2 density  plot and facet approch, facet label" alt="ggplot2 density  plot and facet approch, facet label" width="240" /></p>
</div>
</div>
<div id="ggplot2.density-function" class="section level1">
<h1>ggplot2.density function</h1>
<div id="description" class="section level2">
<h2>Description</h2>
<p>Plot easily a density plot with R package <strong>easyGgplot2</strong>.</p>
</div>
<div id="usage" class="section level2">
<h2>usage</h2>
<pre class="r"><code>ggplot2.density(data, xName, groupName=NULL,
      addMeanLine=FALSE, meanLineColor=NULL,
      meanLineType="dashed", meanLineSize=1,
      densityFill=NULL,fillGroupDensity=FALSE,
      colorGroupDensityLine=FALSE,
      groupColors=NULL, brewerPalette=NULL,faceting=FALSE,...)</code></pre>
</div>
<div id="arguments" class="section level2">
<h2>Arguments</h2>
<table>
<thead>
<tr class="header">
<th align="left">Arguments</th>
<th align="left">Descriptions</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>data</strong></td>
<td align="left">data.frame or a numeric vector. Columns are variables and rows are observations.</td>
</tr>
<tr class="even">
<td align="left"><strong>xName</strong></td>
<td align="left">The name of column containing x variable. Default value is NULL.</td>
</tr>
<tr class="odd">
<td align="left"><strong>groupName</strong></td>
<td align="left">The name of column containing group variable. This variable is used to color plot according to the group.</td>
</tr>
<tr class="even">
<td align="left"><strong>addMeanLine</strong></td>
<td align="left">If TRUE, the mean line is added on the plot for each group. Default value is FALSE.</td>
</tr>
<tr class="odd">
<td align="left"><strong>meanLineColor, meanLineType, meanLineSize</strong></td>
<td align="left">mean line color, type and size.</td>
</tr>
<tr class="even">
<td align="left"><strong>densityFill</strong></td>
<td align="left">Fill color of density plot. This is only considered when groupName=NULL.</td>
</tr>
<tr class="odd">
<td align="left"><strong>fillGroupDensity</strong></td>
<td align="left">If TRUE, density curve of each group is filled. Default value is FALSE.</td>
</tr>
<tr class="even">
<td align="left"><strong>colorGroupDensityLine</strong></td>
<td align="left">If TRUE, density curve line are colored. Default value is FALSE.</td>
</tr>
<tr class="odd">
<td align="left"><strong>groupColors</strong></td>
<td align="left">Color of groups. groupColors should have the same length as groups.</td>
</tr>
<tr class="even">
<td align="left"><strong>brewerPalette</strong></td>
<td align="left">This can be also used to indicate group colors. In this case the parameter groupColors should be NULL. e.g: brewerPalette=“Paired”.</td>
</tr>
<tr class="odd">
<td align="left"><strong>….</strong></td>
<td align="left">Other arguments passed on to ggplot2.customize custom function or to geom_density functions from ggplot2 package.</td>
</tr>
</tbody>
</table>
<p><span class="warning">The other arguments which can be used are described at this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2 customize</a>. They are used to customize the plot (axis, title, background, color, legend, ….) generated <strong>using ggplot2</strong> or <strong>easyGgplot2</strong> R package.</span></p>
</div>
<div id="examples" class="section level2">
<h2>Examples</h2>
<pre class="r"><code>library(easyGgplot2)
#plot
ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,groupName=&amp;#39;sex&amp;#39;,
          groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;),
          mainTitle="Density plot \nper sex",
          xtitle="Weight (kg)", ytitle="Density")

#Or use this
plot<-ggplot2.density(data=weight, xName=&amp;#39;weight&amp;#39;,groupName=&amp;#39;sex&amp;#39;,
                  groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;))
plot<-ggplot2.customize(plot, 
          mainTitle="Density plot \nper sex",
          xtitle="Weight (kg)", ytitle="Density")
print(plot)</code></pre>
</div>
</div>
<div id="easy-ggplot2-ebook" class="section level1">
<h1>Easy ggplot2 ebook</h1>
<p><span class="success">Note that an eBook is available on <strong>easyGgplot2</strong> package <a href="https://www.sthda.com/english/english/download/download-4+easy-ggplot2-book.php">here</a>.</span></p>
<div class="block">
<p>By Alboukadel Kassambara</p>
<p>Copyright 2014 Alboukadel Kassambara. All rights reserved.</p>
<p>Published by STHDA (<a href="https://www.sthda.com/english">https://www.sthda.com/english</a>).</p>
<p>September 2014 : First edition.</p>
<p><strong>Licence</strong> : This document is under creative commons licence (<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">http://creativecommons.org/licenses/by-nc-sa/3.0/</a>).</p>
<p><strong>Contact</strong> : Alboukadel Kassambara <a href="mailto:alboukadel.kassambara@gmail.com">alboukadel.kassambara@gmail.com</a></p>
</div>
<p><br/></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning">This analysis was performed using R (ver. 3.1.0), easyGgplot2 (ver 1.0.0) and ggplot2 (ver 1.0.0).</span></p>
<ul>
<li><a href="http://docs.ggplot2.org/current/">ggplot2 online documentation</a></li>
<li><a href="http://www.cookbook-r.com/Graphs/">Cookbook for R</a></li>
</ul>
</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 Feb 2015 20:50:43 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[ggplot2.lineplot : Easy line plots in R software using ggplot2]]></title>
			<link>https://www.sthda.com/english/wiki/ggplot2-lineplot-easy-line-plots-in-r-software-using-ggplot2</link>
			<guid>https://www.sthda.com/english/wiki/ggplot2-lineplot-easy-line-plots-in-r-software-using-ggplot2</guid>
			<description><![CDATA[<!-- START HTML -->

            
  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">


<div id="TOC">
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#install-and-load-easyggplot2-package">Install and load easyGgplot2 package</a></li>
<li><a href="#data-format">Data format</a></li>
<li><a href="#basic-line-plot">Basic line plot</a></li>
<li><a href="#change-the-line-type-and-the-point-shape-of-line-plot">Change the line type and the point shape of line plot</a></li>
<li><a href="#lineplot-with-more-variables">Lineplot with more variables</a></li>
<li><a href="#customize-your-line-plot">Customize your line plot</a><ul>
<li><a href="#parameters">Parameters</a></li>
<li><a href="#main-title-and-axis-labels">Main title and axis labels</a></li>
<li><a href="#axis-ticks">Axis ticks</a></li>
<li><a href="#background-and-colors">Background and colors</a><ul>
<li><a href="#change-line-plot-background-and-fill-colors">Change line plot background and fill colors</a></li>
<li><a href="#change-line-plot-color-according-to-the-group">Change line plot color according to the group</a></li>
</ul></li>
<li><a href="#legend">Legend</a><ul>
<li><a href="#legend-position">Legend position</a></li>
<li><a href="#legend-background-color-title-and-text-font-styles">Legend background color, title and text font styles</a></li>
</ul></li>
<li><a href="#axis-scales">Axis scales</a></li>
<li><a href="#create-a-customized-plots-with-few-r-code">Create a customized plots with few R code</a></li>
</ul></li>
<li><a href="#line-plot-with-a-numeric-x-axis">Line plot with a numeric x-axis</a></li>
<li><a href="#ggplot2.lineplot-function">ggplot2.lineplot function</a><ul>
<li><a href="#description">Description</a></li>
<li><a href="#usage">usage</a></li>
<li><a href="#arguments">Arguments</a></li>
<li><a href="#examples">Examples</a></li>
</ul></li>
<li><a href="#easy-ggplot2-ebook">Easy ggplot2 ebook</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<div id="introduction" class="section level1">
<h1>Introduction</h1>
<p><strong>ggplot2.lineplot</strong> is an easy to use function to generate <strong>line plots</strong> in <strong>R software</strong> using <strong>ggplot2</strong> plotting system. It can also be used to <strong>customize</strong> quickly the plot parameters including <strong>main title</strong>, <strong>axis labels</strong>, <strong>legend</strong>, <strong>background</strong> and <strong>colors</strong>. <strong>ggplot2.lineplot</strong> function is from <a href="https://www.sthda.com/english/english/wiki/easyggplot2"><strong>easyGgplot2</strong></a> package. An R script is available in the next section to install the package.</p>
<p>The aim of this article is to show you step by step, how to plot and customize a <strong>line plot</strong> using ggplot2.lineplot function.</p>
<p>At the end of this <strong>tutorial</strong> you will be able to draw, with few R code, the following plots:</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-demo1.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="336" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-demo2.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="336" /></p>

<p><span class="warning"><strong>ggplot2.lineplot</strong> function is described in detail at the end of this document.</span></p>
</div>
<div id="install-and-load-easyggplot2-package" class="section level1">
<h1>Install and load easyGgplot2 package</h1>
<p><strong>easyGgplot2</strong> R package can be installed as follow :</p>
<pre class="r"><code>install.packages("devtools")
library(devtools)
install_github("easyGgplot2", "kassambara")</code></pre>
<p>Load the package using this R code :</p>
<pre class="r"><code>library(easyGgplot2)</code></pre>
</div>
<div id="data-format" class="section level1">
<h1>Data format</h1>
<p><span class="success">The data must be a numeric vector or a data.frame (columns are variables and rows are observations).</span></p>
<p><code>restaurant</code> data from easyGgplot2 package will be used in the following example.</p>
<pre class="r"><code>#data.frame
head(restaurant)</code></pre>
<pre><code>##      sex   time total_bill
## 1 Female  Lunch      13.53
## 2 Female Dinner      16.81
## 3   Male  Lunch      16.24
## 4   Male Dinner      17.42</code></pre>
</div>
<div id="basic-line-plot" class="section level1">
<h1>Basic line plot</h1>
<p>A subset of <code>restaurant</code> data is used :</p>
<pre class="r"><code>df<-restaurant[c(1,4), c("time", "total_bill")]
head(df)</code></pre>
<pre><code>##     time total_bill
## 1  Lunch      13.53
## 4 Dinner      17.42</code></pre>
<pre class="r"><code># Basic line plot of the values of "total_bill" variables
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;)

# Add points
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;, 
                 addPoint=TRUE)

# Use the arrow parameter to add an arrow to the line
# See ?grid::arrow for more details
rquery.loadPackages("grid")
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
                 arrow=arrow())

# Add closed arrow to the to end of the line
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
                 arrow=arrow(angle = 15, ends = "both",
                             type = "closed")
                 )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-basic-lineplot1.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-basic-lineplot2.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-basic-lineplot3.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-basic-lineplot4.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="change-the-line-type-and-the-point-shape-of-line-plot" class="section level1">
<h1>Change the line type and the point shape of line plot</h1>
<p><span class="warning">Different <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">point shapes</a> and <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">line types</a> can be used in the plot. By default, ggplot2 uses solid line type and circle shape.</span></p>
<ul>
<li>The different <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">point shapes</a> in R are described <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">here</a>.</li>
<li>The available <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">line types</a> are shown <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">here</a>.</li>
</ul>
<pre class="r"><code># Change color of both line and points
# Change line type and point type, 
  #and use thicker line and larger points
# Change points to circles with white fill
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
             #line color, type and size
             color="red", linetype="dotted", size=1.5,
             addPoint=TRUE, pointSize=4, pointShape=21,
             pointFill="white", pointColor="red")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-linetype.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="lineplot-with-more-variables" class="section level1">
<h1>Lineplot with more variables</h1>
<p>This data will be used for the examples below:</p>
<pre class="r"><code>df1 <- restaurant
head(df1)</code></pre>
<pre><code>##      sex   time total_bill
## 1 Female  Lunch      13.53
## 2 Female Dinner      16.81
## 3   Male  Lunch      16.24
## 4   Male Dinner      17.42</code></pre>
<pre class="r"><code># Plot of variable &amp;#39;total_bill&amp;#39; according to xName &amp;#39;time&amp;#39;.
# The plot is colored by the groupName &amp;#39;sex&amp;#39;
# line type and point shape are set by the groupName &amp;#39;sex&amp;#39;
ggplot2.lineplot(data=df1, xName=&amp;#39;time&amp;#39;, yName="total_bill",
               groupName=&amp;#39;sex&amp;#39;, addPoint=TRUE,
               legendPosition="top")

# Use the same linetype and point shape 
# but different colors by group
ggplot2.lineplot(data=df1, xName=&amp;#39;time&amp;#39;, yName="total_bill",
                 groupName=&amp;#39;sex&amp;#39;,legendPosition="top",
                 linetype="solid",addPoint=TRUE, shape=19)

# Basic plot with black color and
# differents point shapes by group
ggplot2.lineplot(data=df1, xName=&amp;#39;time&amp;#39;, yName="total_bill", 
             groupName=&amp;#39;sex&amp;#39;,legendPosition="top",
             linetype="solid",addPoint=TRUE, color="black")

# Set point shape manually
ggplot2.lineplot(data=df1, xName=&amp;#39;time&amp;#39;, yName="total_bill",
       groupName=&amp;#39;sex&amp;#39;,legendPosition="top",
       linetype="solid",addPoint=TRUE, color="black",
       pointSize=3, pointFill="white")+
              scale_shape_manual(values=c(22,21))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-multiple-variables1.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-multiple-variables2.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-multiple-variables3.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-multiple-variables4.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="customize-your-line-plot" class="section level1">
<h1>Customize your line plot</h1>
<div id="parameters" class="section level2">
<h2>Parameters</h2>
<p>The arguments that can be used to customize x and y axis are listed below :</p>
<table>
<thead>
<tr class="header">
<th align="left">Parameters</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>mainTitle</strong></td>
<td align="left">the title of the plot</td>
</tr>
<tr class="even">
<td align="left"><strong>mainTitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style (“italic”, “bold”, “bold.italic”) and the color of x and y axis titles. Default value is: mainTitleFont=c(14, “bold”, “black”).</td>
</tr>
<tr class="odd">
<td align="left"><strong>xShowTitle, yShowTitle</strong></td>
<td align="left">if TRUE, x and y axis titles will be shown. Set the value to FALSE to hide axis labels. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtitle, ytitle</strong></td>
<td align="left">x and y axis labels. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xtitleFont, ytitleFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis titles. Possible values for the <strong>style</strong>:“plain”, “italic”, “bold”, “bold.italic”. Color can be specified as an hexadecimal code (e.g: “#FFCC00”) or by the name (e.g : “red”, “green”). Default values are <code>xtitleFont=c(14,"bold", "black"), ytitleFont=c(14,"bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xlim, ylim</strong></td>
<td align="left">limit for the x and y axis. Default values are <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xScale, yScale</strong></td>
<td align="left">x and y axis scales. Possible values : c(“none”, “log2”, “log10”). e.g: yScale=“log2”. Default values are <code>NULL</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xShowTickLabel, yShowTickLabel</strong></td>
<td align="left">if TRUE, x and y axis tick mark labels will be shown. Default values are <code>TRUE</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xTickLabelFont, yTickLabelFont</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the style and the color of x and y axis tick label fonts. Default value are <code>xTickLabelFont=c(12, "bold", "black"), yTickLabelFont=c(12, "bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtickLabelRotation, ytickLabelRotation</strong></td>
<td align="left">Rotation angle of x and y axis tick labels. Default value are <code>0</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>hideAxisTicks</strong></td>
<td align="left">if TRUE, x and y axis ticks are hidden. Default value is <code>FALSE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>axisLine</strong></td>
<td align="left">a vector of length 3 indicating respectively the size, the line type and the color of axis lines. Default value is <code>c(0.5, "solid", "#E5E5E5")</code>.</td>
</tr>
</tbody>
</table>
<p>For more details follow this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2.customize</a>.</p>
</div>
<div id="main-title-and-axis-labels" class="section level2">
<h2>Main title and axis labels</h2>
<pre class="r"><code># Change main title and axis titles
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
                mainTitle="Total bill\n per time of day",
                xtitle="Time of day", ytitle="Total bill")

# Customize title styles. Possible values for the font style :
  # &amp;#39;plain&amp;#39;, &amp;#39;italic&amp;#39;, &amp;#39;bold&amp;#39;, &amp;#39;bold.italic&amp;#39;.
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
                mainTitle="Total bill\n per time of day",
                xtitle="Time of day", ytitle="Total bill",
                mainTitleFont=c(14,"bold.italic", "red"),
                xtitleFont=c(14,"bold", "#993333"),
                ytitleFont=c(14,"bold", "#993333"))

# Hide x an y axis titles
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
                xShowTitle=FALSE, yShowTitle=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-main-title-and-axis-labels1.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-main-title-and-axis-labels2.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-main-title-and-axis-labels3.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="axis-ticks" class="section level2">
<h2>Axis ticks</h2>
<pre class="r"><code># Axis ticks labels and orientaion
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
            xShowTitle=FALSE, yShowTitle=FALSE,
            xTickLabelFont=c(14,"bold", "#993333"),
            yTickLabelFont=c(14,"bold", "#993333"),
            xtickLabelRotation=45, ytickLabelRotation=45)

# Hide axis tick labels
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
          xShowTitle=FALSE, yShowTitle=FALSE,
          xShowTickLabel=FALSE, yShowTickLabel=FALSE)

# Hide axis ticks
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
          xShowTitle=FALSE, yShowTitle=FALSE,
          xShowTickLabel=FALSE, yShowTickLabel=FALSE,
          hideAxisTicks=TRUE)

# AxisLine : a vector of length 3 indicating the size,
  #the line type and the color of axis lines
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
                 axisLine=c(1, "solid", "darkblue"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-axis-ticks1.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-axis-ticks2.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-axis-ticks3.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-axis-ticks4.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="163.2" /></p>
</div>
<div id="background-and-colors" class="section level2">
<h2>Background and colors</h2>
<div id="change-line-plot-background-and-fill-colors" class="section level3">
<h3>Change line plot background and fill colors</h3>
<pre class="r"><code># change background color to "white". Default is "gray"
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
            backgroundColor="white")

# Change background color to "lightblue" and grid color to "white"
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
            backgroundColor="lightblue", gridColor="white")

# Remove grid; Remove Top and right border around the plot
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
          backgroundColor="white", fill=&amp;#39;#FFAAD4&amp;#39;, color="black",
          removePanelGrid=TRUE,removePanelBorder=TRUE,
          axisLine=c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-background-color1.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-background-color2.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="163.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-background-color3.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="163.2" /></p>
</div>
<div id="change-line-plot-color-according-to-the-group" class="section level3">
<h3>Change line plot color according to the group</h3>
<p><span class="warning">Colors can be specified as a hexadecimal RGB triplet, such as <code>"#FFCC00"</code> or by names (e.g : <code>"red"</code> ). You can also use other color scales, such as ones taken from the RColorBrewer package. The different <a href="https://www.sthda.com/english/english/wiki/colors-in-r">color systems</a> available in R have been described in detail <a href="https://www.sthda.com/english/english/wiki/colors-in-r">here</a>.<span></p>
<p><span class="success">To change <strong>line plot</strong> color according to the group, you have to specify the name of the data column containing the groups using the argument <code>groupName</code>. Use the argument <code>groupColors</code>, to specify colors by <code>hexadecimal</code> code or by <code>name</code>. In this case, the length of groupColors should be the same as the number of the groups. Use the argument <code>brewerPalette</code>, to specify colors using <code>RColorBrewer</code>palette.</span></p>
<pre class="r"><code># Color the line plot by groupName
ggplot2.lineplot(data=df1, xName=&amp;#39;time&amp;#39;, yName="total_bill",
          groupName=&amp;#39;sex&amp;#39;, size=2)

# Change group colors using hexadecimal colors;
ggplot2.lineplot(data=df1, xName=&amp;#39;time&amp;#39;, yName="total_bill",
          groupName=&amp;#39;sex&amp;#39;,size=2,
          backgroundColor="white", #background and line colors
          groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;))
                

# Change group colors using brewer palette: "Paired"
ggplot2.lineplot(data=df1, xName=&amp;#39;time&amp;#39;, yName="total_bill",
          groupName=&amp;#39;sex&amp;#39;,size=2,
          backgroundColor="white", #background and line colors
          brewerPalette="Paired")

# Change group colors using color names
ggplot2.lineplot(data=df1, xName=&amp;#39;time&amp;#39;, yName="total_bill",
          groupName=&amp;#39;sex&amp;#39;,size=2,
          backgroundColor="white", #background and line colors
          groupColors=c(&amp;#39;aquamarine3&amp;#39;,&amp;#39;chartreuse1&amp;#39;))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-line-plot-color1.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-line-plot-color2.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-line-plot-color3.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-line-plot-color4.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /></p>
</div>
</div>
<div id="legend" class="section level2">
<h2>Legend</h2>
<div id="legend-position" class="section level3">
<h3>Legend position</h3>
<pre class="r"><code># Change the legend position to "top" 
  # (possible values: "left","top", "right", "bottom")
ggplot2.lineplot(data=df1, xName=&amp;#39;time&amp;#39;, yName="total_bill",
                groupName=&amp;#39;sex&amp;#39;,legendPosition="top")
                
# legendPosition can be also a numeric vector c(x, y)
ggplot2.lineplot(data=df1, xName=&amp;#39;time&amp;#39;, yName="total_bill",
                groupName=&amp;#39;sex&amp;#39;, legendPosition=c(0.8,0.2))
                
# Remove plot legend
ggplot2.lineplot(data=df1, xName=&amp;#39;time&amp;#39;, yName="total_bill",
                 groupName=&amp;#39;sex&amp;#39;,showLegend=FALSE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-legend-position1.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-legend-position2.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-legend-position3.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /></p>
<p><span class="warning">It is also possible to position the legend inside the plotting area. You have to indicate the x, y coordinates of legend box. x and y values must be between 0 and 1. c(0,0) corresponds to <strong>“bottom left”</strong> and c(1,1) corresponds to <strong>“top right”</strong> position.</span></p>
</div>
<div id="legend-background-color-title-and-text-font-styles" class="section level3">
<h3>Legend background color, title and text font styles</h3>
<pre class="r"><code># Change legend background color, title and text font styles
ggplot2.lineplot(data=df1, xName=&amp;#39;time&amp;#39;, yName="total_bill",
        groupName=&amp;#39;sex&amp;#39;,
        #legendPosition=c("right", "left","top", "bottom")
        legendPosition="right",
        #legendTitleFont=c(size, style, color)
        legendTitle="Time", legendTitleFont=c(10, "bold", "blue"),
        #legendTextFont=c(size, style, color)
        legendTextFont=c(10, "bold.italic", "red"),
        #legendBackground: c(fill, lineSize, lineType, lineColor)
        legendBackground=c("lightblue", 0.5, "solid", "darkblue" )
        )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-legend-background-and-title.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="336" /></p>
</div>
</div>
<div id="axis-scales" class="section level2">
<h2>Axis scales</h2>
<p>Possible values for y axis scale are “none”, “log2” and log10. Default value is “none”.</p>
<pre class="r"><code># Change x axis limit
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
                 ylim=c(0,18))
                
# y Log scale. yScale="log2". 
# Possible value="none", "log2" and "log10"
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
                 yScale="log2")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-axis-scale1.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-axis-scale2.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="create-a-customized-plots-with-few-r-code" class="section level2">
<h2>Create a customized plots with few R code</h2>
<pre class="r"><code># Customized lineplot
ggplot2.lineplot(data=df1, xName="time", yName=&amp;#39;total_bill&amp;#39;,
        groupName="sex",size=2,
        addPoint=TRUE, pointSize=4, backgroundColor="white",
        color="black",
        xtitle="Time of day", ytitle="Total bill",
        mainTitle="Total bill per time of day")           
               
# Remove grid; Remove Top and right border around the plot;
# different colors per group 
ggplot2.lineplot(data=df1, xName="time", yName=&amp;#39;total_bill&amp;#39;, 
        groupName="sex",size=2,
        addPoint=TRUE, pointSize=4, backgroundColor="white", 
        groupColors=c(&amp;#39;#999999&amp;#39;,&amp;#39;#E69F00&amp;#39;),
        xtitle="Time of day", ytitle="Total bill",
        mainTitle="Total bill per time of day",            
        removePanelGrid=TRUE,removePanelBorder=TRUE,
        axisLine=c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-customized-plot1.png" title="ggplot2 lineplot" alt="ggplot2 lineplot" width="336" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-customized-plot2.png" title="ggplot2 lineplot" alt="ggplot2 lineplot" width="336" /></p>
</div>
</div>
<div id="line-plot-with-a-numeric-x-axis" class="section level1">
<h1>Line plot with a numeric x-axis</h1>
<p>When the variable on the x-axis is numeric, it is sometimes useful to treat it as continuous, and sometimes useful to treat it as categorical. In this data set, the dose is a numeric variable with values 0.5, 1.0, and 2.0. It might be useful to treat these values as equal categories when making a graph.</p>
<p>This is derived from the <strong>ToothGrowth</strong> dataset included with R.</p>
<pre class="r"><code>dfn <- read.table(header=T, text=&amp;#39;
supp dose length
  OJ  0.5  13.23
  OJ  1.0  22.70
  OJ  2.0  26.06
  VC  0.5   7.98
  VC  1.0  16.77
  VC  2.0  26.14
&amp;#39;)

# line plot with x-axis treated as continuous
ggplot2.lineplot(data=dfn, xName="dose", yName=&amp;#39;length&amp;#39;,
               groupName="supp", 
               addPoint=TRUE, xAxisType="continuous")

# With x-axis treated as categorical
ggplot2.lineplot(data=dfn, xName="dose", yName=&amp;#39;length&amp;#39;,
               groupName="supp", 
               addPoint=TRUE, xAxisType="categorical")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-line-plot-with-numeric-x-axis1.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/easy-ggplot2/ggplot2-line-plot-line-plot-with-numeric-x-axis2.png" title="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" alt="Data visualization with ggplot2 line plots : tutorial on how to use ggplot2.lineplot function to easily make line graphs using ggplot2 and R statistical software" width="240" /></p>
</div>
<div id="ggplot2.lineplot-function" class="section level1">
<h1>ggplot2.lineplot function</h1>
<div id="description" class="section level2">
<h2>Description</h2>
<p>Plot easily a line plot using <strong>easyGgplot2</strong> R package.</p>
</div>
<div id="usage" class="section level2">
<h2>usage</h2>
<pre class="r"><code>ggplot2.lineplot(data, xName, yName,  groupName=NULL,
         addPoint=FALSE, pointSize=1.5, pointShape=19,
         pointFill=NULL, pointColor="black",
         arrow=NULL, xAxisType=c("categorical", "continuous"),                     
         groupColors=NULL, brewerPalette=NULL,...)</code></pre>
</div>
<div id="arguments" class="section level2">
<h2>Arguments</h2>
<table>
<thead>
<tr class="header">
<th align="left">Arguments</th>
<th align="left">Descriptions</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>data</strong></td>
<td align="left">data.frame or a numeric vector. Columns are variables and rows are observations.</td>
</tr>
<tr class="even">
<td align="left"><strong>xName</strong></td>
<td align="left">The name of column containing x variable (i.e groups).</td>
</tr>
<tr class="odd">
<td align="left"><strong>yName</strong></td>
<td align="left">The name of column containing y variable.</td>
</tr>
<tr class="even">
<td align="left"><strong>groupName</strong></td>
<td align="left">The name of column containing group variable. This variable is used to color plot according to the group.</td>
</tr>
<tr class="odd">
<td align="left"><strong>addPoint</strong></td>
<td align="left">If TRUE, points are added to the plot. Default value is FALSE.</td>
</tr>
<tr class="even">
<td align="left"><strong>pointSize, pointShape, pointFill, pointColor</strong></td>
<td align="left">Modify point size, shape, fill and color.</td>
</tr>
<tr class="odd">
<td align="left"><strong>arrow</strong></td>
<td align="left">arrow is function from package grid. This function Describe arrows to add to a line. See ?grid::arrow for more details. Usage : arrow=arrow(). Default value is NULL.</td>
</tr>
<tr class="even">
<td align="left"><strong>xAxisType</strong></td>
<td align="left">Indicate the type of x-axis. Possible values =c(“categorical”, “continuous”). Default value is “categorical”. When the variable on the x-axis is numeric, it is sometimes useful to treat it as continuous, and sometimes useful to treat it as categorical.</td>
</tr>
<tr class="odd">
<td align="left"><strong>groupColors</strong></td>
<td align="left">Color of groups. groupColors should have the same length as groups.</td>
</tr>
<tr class="even">
<td align="left"><strong>brewerPalette</strong></td>
<td align="left">This can be also used to indicate group colors. In this case the parameter groupColors should be NULL. e.g: brewerPalette=“Paired”.</td>
</tr>
<tr class="odd">
<td align="left"><strong>….</strong></td>
<td align="left">Other arguments passed on to ggplot2.customize custom function or to geom_line functions from ggplot2 package.</td>
</tr>
</tbody>
</table>
<p><span class="warning">The other arguments which can be used are described at this link : <a href="https://www.sthda.com/english/english/wiki/ggplot2-customize-how-to-personalize-easily-ggplot2-graphs-in-r-statistical-software">ggplot2 customize</a>. They are used to customize the plot (axis, title, background, color, legend, ….) generated <strong>using ggplot2</strong> or <strong>easyGgplot2</strong> R package.</span></p>
</div>
<div id="examples" class="section level2">
<h2>Examples</h2>
<pre class="r"><code>library(easyGgplot2)
#data
df<-restaurant[c(1,4), c("time", "total_bill")]

#plot
ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;,
          mainTitle="Plot of total bill\n per time of day",
          xtitle="Time of day", ytitle="Total bill")

#Or use this
plot<-ggplot2.lineplot(data=df, xName="time", yName=&amp;#39;total_bill&amp;#39;)
plot<-ggplot2.customize(plot,  
          mainTitle="Plot of total bill\n per time of day",
          xtitle="Time of day", ytitle="Total bill")
print(plot)</code></pre>
</div>
</div>
<div id="easy-ggplot2-ebook" class="section level1">
<h1>Easy ggplot2 ebook</h1>
<p><span class="success">Note that an eBook is available on <strong>easyGgplot2</strong> package <a href="https://www.sthda.com/english/english/download/download-4+easy-ggplot2-book.php">here</a>.</span></p>
<div class="block">
<p>By Alboukadel Kassambara</p>
<p>Copyright 2014 Alboukadel Kassambara. All rights reserved.</p>
<p>Published by STHDA (<a href="https://www.sthda.com/english">https://www.sthda.com/english</a>).</p>
<p>September 2014 : First edition.</p>
<p><strong>Licence</strong> : This document is under creative commons licence (<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">http://creativecommons.org/licenses/by-nc-sa/3.0/</a>).</p>
<p><strong>Contact</strong> : Alboukadel Kassambara <a href="mailto:alboukadel.kassambara@gmail.com">alboukadel.kassambara@gmail.com</a></p>
</div>
<p><br/></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning">This analysis was performed using R (ver. 3.1.0), easyGgplot2 (ver 1.0.0) and ggplot2 (ver 1.0.0).</span></p>
<ul>
<li><a href="http://docs.ggplot2.org/current/">ggplot2 online documentation</a></li>
<li><a href="http://www.cookbook-r.com/Graphs/">Cookbook for R</a></li>
</ul>
</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 Feb 2015 20:49:06 +0100</pubDate>
			
		</item>
		
	</channel>
</rss>
