<?xml version="1.0" encoding="UTF-8" ?>
<!-- RSS generated by PHPBoost on Sat, 16 May 2026 07:17:11 +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/23" rel="self" type="application/rss+xml"/>
		<link>https://www.sthda.com</link>
		<description><![CDATA[Last articles of the category: Graphical parameters]]></description>
		<copyright>(C) 2005-2026 PHPBoost</copyright>
		<language>en</language>
		<generator>PHPBoost</generator>
		
		
		<item>
			<title><![CDATA[Graphical parameters]]></title>
			<link>https://www.sthda.com/english/wiki/graphical-parameters</link>
			<guid>https://www.sthda.com/english/wiki/graphical-parameters</guid>
			<description><![CDATA[<!-- START HTML -->

            
  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">



<div id="TOC">
<ul>
<li><a href="#add-and-customize-titles">Add and customize titles</a></li>
<li><a href="#add-legends">Add legends</a></li>
<li><a href="#add-texts">Add texts</a></li>
<li><a href="#add-straight-lines">Add straight lines</a></li>
<li><a href="#add-an-axis-to-a-plot">Add an axis to a plot</a></li>
<li><a href="#change-axis-scale-minimum-maximum-and-log-scale">Change axis scale : minimum, maximum and log scale</a></li>
<li><a href="#customize-tick-mark-labels">Customize tick mark labels</a></li>
<li><a href="#change-plotting-symbols">Change plotting symbols</a></li>
<li><a href="#change-line-types">Change line types</a></li>
<li><a href="#change-colors">Change colors</a></li>
<li><a href="#related-articles">Related articles</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>This article provides a quick start guide to change and customize <strong>R</strong> <strong>graphical parameters</strong>, including:</p>
<ul>
<li>adding <strong>titles</strong>, <strong>legends</strong>, <strong>texts</strong>, <strong>axis</strong> and <strong>straight lines</strong></li>
<li>changing <strong>axis scales</strong>, <strong>plotting symbols</strong>, <strong>line types</strong> and <strong>colors</strong></li>
</ul>
<p>For each of these <strong>graphical parameters</strong>, you will learn the simplified format of the R functions to use and some examples.</p>
<br/>
<div class="block">
<ul>
<li><a href="https://www.sthda.com/english/english/wiki/add-titles-to-a-plot-in-r-software">Add and customize titles</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/add-legends-to-plots-in-r-software-the-easiest-way">Add and customize legends</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/add-text-to-a-plot-in-r-software">Add texts</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/abline-r-function-an-easy-way-to-add-straight-lines-to-a-plot-using-r-software">Add straight lines: vertical, horizontal and regression lines</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/wiki/add-an-axis-to-a-plot-with-r-software">Add an axis</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/axis-scale-in-r-software-minimum-maximum-and-log-scale">Change axis scale: minimum, maximum and log scale</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/add-custom-tick-mark-labels-to-a-plot-in-r-software">Customize tick mark labels</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">Change point shapes</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">Change line types</a></li>
<li><a href="https://www.sthda.com/english/english/wiki/colors-in-r">Change colors</a></li>
</ul>
</div>
<p><br/></p>
<hr/>
<div id="add-and-customize-titles" class="section level1">
<h1>Add and customize titles</h1>
<p><span class="question">How this chapter is organized?</span></p>
<ul>
<li>Change <strong>main title</strong> and <strong>axis labels</strong></li>
<li><strong>title colors</strong></li>
<li>The <strong>font style</strong> for titles</li>
<li>Change the <strong>font size</strong></li>
<li>Use the <strong>title</strong>() function</li>
<li>Customize the titles using <strong>par</strong>() function.</li>
</ul>
<p><span class="success"><i class="fa fa-plus-circle"></i> Read more —> <a href="https://www.sthda.com/english/english/wiki/add-titles-to-a-plot-in-r-software">Add titles to a plot in R software</a>.</span></p>
<p><strong>Plot titles</strong> can be specified either directly to the <strong>plotting functions</strong> during the plot creation or by using the <strong>title()</strong> function (to add titles on an existing plot).</p>
<pre class="r"><code># Add titles
barplot(c(2,5), main="Main title",
        xlab="X axis title",
        ylab="Y axis title",
        sub="Sub-title",
        col.main="red", col.lab="blue", col.sub="black")

# Increase the size of titles
barplot(c(2,5), main="Main title",
        xlab="X axis title",
        ylab="Y axis title",
        sub="Sub-title",
        cex.main=2, cex.lab=1.7, cex.sub=1.2)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-add-titles-to-a-plot-1.png" title="" alt="" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-add-titles-to-a-plot-2.png" title="" alt="" width="144" /></p>
<p><span class="success"><i class="fa fa-plus-circle"></i> Read more —> <a href="https://www.sthda.com/english/english/wiki/add-titles-to-a-plot-in-r-software">Add titles to a plot in R software</a>. </span></p>
</div>
<div id="add-legends" class="section level1">
<h1>Add legends</h1>
<p><span class="question">How this chapter is organized?</span></p>
<ul>
<li>R legend function</li>
<li>Title, text font and background color of the legend box</li>
<li>Border of the legend box</li>
<li>Specify legend position by keywords</li>
</ul>
<p><span class="success"><i class="fa fa-plus-circle"></i> Read more —> <a href="https://www.sthda.com/english/english/wiki/add-legends-to-plots-in-r-software-the-easiest-way">Add legends to plots</a></span></p>
<p>The <strong>legend()</strong> function can be used. A simplified format is :</p>
<pre class="r"><code>legend(x, y=NULL, legend, col)</code></pre>
<br/>
<div class="block">
<ul>
<li><strong>x and y</strong> : the co-ordinates to be used for the legend. Keywords can also be used for x : “bottomright”, “bottom”, “bottomleft”, “left”, “topleft”, “top”, “topright”, “right” and “center”.</li>
<li><strong>legend</strong> : the text of the legend</li>
<li><strong>col</strong> : colors of lines and points beside the text for legends</li>
</ul>
</div>
<p><br/></p>
<pre class="r"><code># Generate some data
x<-1:10; y1=x*x; y2=2*y1
# First line plot
plot(x, y1, type="b", pch=19, col="red", xlab="x", ylab="y")
# Add a second line
lines(x, y2, pch=18, col="blue", type="b", lty=2)
# Add legends
legend("topleft", legend=c("Line 1", "Line 2"),
       col=c("red", "blue"), lty=1:2, cex=0.8)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-add-legnds-to-plots-1.png" title="" alt="" width="268.8" /></p>
<p><span class="success"><i class="fa fa-plus-circle"></i> Read more —> <a href="https://www.sthda.com/english/english/wiki/add-legends-to-plots-in-r-software-the-easiest-way">Add legends to plots</a></span></p>
</div>
<div id="add-texts" class="section level1">
<h1>Add texts</h1>
<p><span class="question">How this chapter is organized?</span></p>
<ul>
<li>Add texts within the graph</li>
<li>Add text in the margins of the graph</li>
<li>Add mathematical annotation to a plot</li>
</ul>
<p><span class="success"><i class="fa fa-plus-circle"></i> Read more —> <a href="https://www.sthda.com/english/english/wiki/add-text-to-a-plot-in-r-software">Add text to a plot</a></span></p>
<p>To <strong>add a text</strong> to a plot in R, the <strong>text()</strong> function [to draw a text inside the plotting area] and <strong>mtext()</strong>[to put a text in one of the four margins of the plot] function can be used.</p>
<p>A simplified format for <strong>text()</strong> is :</p>
<pre class="r"><code>text(x, y, labels)</code></pre>
<br/>
<div class="block">
<ul>
<li>x and y are the coordinates of the texts</li>
<li>labels : vector of texts to be drawn</li>
</ul>
</div>
<p><br/></p>
<pre class="r"><code>plot(cars[1:10,], pch=19)
text(cars[1:10,],  row.names(cars[1:10,]), 
     cex=0.65, pos=1,col="red") </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-add-text-to-a-plots-1.png" title="" alt="" width="192" /></p>
<p><span class="success"><i class="fa fa-plus-circle"></i> Read more —> <a href="https://www.sthda.com/english/english/wiki/add-text-to-a-plot-in-r-software">Add text to a plot</a></span></p>
</div>
<div id="add-straight-lines" class="section level1">
<h1>Add straight lines</h1>
<p><span class="question">How this chapter is organized?</span></p>
<ul>
<li>Add a vertical line</li>
<li>Add an horizontal line</li>
<li>Add regression line</li>
</ul>
<p><span class="success"><i class="fa fa-plus-circle"></i> Read more —> <a href="https://www.sthda.com/english/english/wiki/abline-r-function-an-easy-way-to-add-straight-lines-to-a-plot-using-r-software">abline R function : An easy way to add straight lines to a plot using R software</a></span></p>
<p>The R function <strong>abline()</strong> can be used to add straight lines (vertical, horizontal or regression lines) to a graph.</p>
<p>A simplified format is :</p>
<pre class="r"><code>abline(a=NULL, b=NULL, h=NULL, v=NULL, ...)</code></pre>
<br/>
<div class="block">
<ul>
<li><strong>a, b</strong> : single values specifying the <strong>intercept</strong> and the <strong>slope</strong> of the line</li>
<li><strong>h</strong> : the <strong>y-value(s)</strong> for horizontal line(s)</li>
<li><strong>v</strong> : the <strong>x-value(s)</strong> for vertical line(s)</li>
</ul>
</div>
<p><br/></p>
<pre class="r"><code># Add horizontal and vertical lines
#++++++++++++++++++++++++++++++++++
plot(cars, pch=19)
abline(v=15, col="blue") # Add vertical line
# Add horizontal line, change line color, size and type
abline(h=60, col="red", lty=2, lwd=3)

# Fit regression line
#++++++++++++++++++++++++++++++++++
require(stats)
reg<-lm(dist ~ speed, data = cars)
coeff=coefficients(reg)
# equation of the regression line : 
eq = paste0("y = ", round(coeff[2],1), "*x ", round(coeff[1],1))
plot(cars, main=eq, pch=18)
abline(reg, col="blue", lwd=2)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-add-lines-to-a-plot-1.png" title="" alt="" width="259.2" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-add-lines-to-a-plot-2.png" title="" alt="" width="259.2" /></p>
<p><span class="success"><i class="fa fa-plus-circle"></i> Read more —> <a href="https://www.sthda.com/english/english/wiki/abline-r-function-an-easy-way-to-add-straight-lines-to-a-plot-using-r-software">abline R function : An easy way to add straight lines to a plot using R software</a></span></p>
</div>
<div id="add-an-axis-to-a-plot" class="section level1">
<h1>Add an axis to a plot</h1>
<p><strong>axis()</strong> function can be used.</p>
<p>A simplified format is :</p>
<pre class="r"><code>axis(side, at=NULL, labels=TRUE)</code></pre>
<br/>
<div class="block">
<ul>
<li><strong>side</strong> : the side of the graph the axis is to be drawn on; Possible values are <strong>1</strong>(below), <strong>2</strong>(left), <strong>3</strong>(above) and <strong>4</strong>(right).</li>
<li><strong>at</strong>: the points at which tick-marks are to be drawn.</li>
<li><strong>labels</strong>: vector of texts for the labels of tick-marks.</li>
</ul>
</div>
<p><br/></p>
<pre class="r"><code>x<-1:4; y=x*x
plot(x, y, pch=18, col="red", type="b",
     frame=FALSE, xaxt="n") # Remove x axis
axis(1, 1:4, LETTERS[1:4], col.axis="blue")
axis(3, col = "darkgreen", lty = 2, lwd = 0.5)
axis(4, col = "violet", col.axis = "dark violet", lwd = 2)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-add-axis-to-a-plot-1.png" title="" alt="" width="240" /></p>
<p><span class="success"><i class="fa fa-plus-circle"></i> Read more —> <a href="https://www.sthda.com/english/english/wiki/add-an-axis-to-a-plot-with-r-software">Add an axis to a plot with R software</a>.</span></p>
</div>
<div id="change-axis-scale-minimum-maximum-and-log-scale" class="section level1">
<h1>Change axis scale : minimum, maximum and log scale</h1>
<p><strong>xlim</strong> and <strong>ylim</strong> arguments can be used to change the limits for x and y axis. Format : <strong>xlim = c(min, max)</strong>; <strong>ylim = c(min, max)</strong>.</p>
<p><strong>log</strong> transformation can be performed using the parameters : <strong>log=“x”, log=“y” or log=“xy”</strong>.</p>
<pre class="r"><code>x<-1:10; y=x*x
plot(x, y) # Simple graph
plot(x, y, xlim=c(1,15), ylim=c(1,150))# Enlarge the scale
plot(x, y, log="y")# Log scale</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-change-axis-scale-1.png" title="" alt="" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-change-axis-scale-2.png" title="" alt="" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-change-axis-scale-3.png" title="" alt="" width="144" /></p>
<p><span class="success"><i class="fa fa-plus-circle"></i> Read more —> <a href="https://www.sthda.com/english/english/wiki/axis-scale-in-r-software-minimum-maximum-and-log-scale">Axis scale in R software : minimum, maximum and log scale</a>.</span></p>
</div>
<div id="customize-tick-mark-labels" class="section level1">
<h1>Customize tick mark labels</h1>
<ul>
<li>Color, font style and font size of tick mark labels :</li>
<li>Orientation of tick mark labels</li>
<li>Hide tick marks</li>
<li>Change the string rotation of tick mark labels</li>
<li>Use the par() function</li>
</ul>
<pre class="r"><code>x<-1:10; y<-x*x
# Simple graph
plot(x, y)
# Custom plot : blue text, italic-bold, magnification
plot(x,y, col.axis="blue", font.axis=4, cex.axis=1.5)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-tick-mark-labels-1.png" title="" alt="" width="192" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-tick-mark-labels-2.png" title="" alt="" width="192" /></p>
<p><span class="success"><i class="fa fa-plus-circle"></i> Read more —> <a href="https://www.sthda.com/english/english/wiki/add-custom-tick-mark-labels-to-a-plot-in-r-software">Customize tick mark labels</a>.</span></p>
</div>
<div id="change-plotting-symbols" class="section level1">
<h1>Change plotting symbols</h1>
<p>The following <strong>points symbols</strong> can be used in <strong>R</strong> :</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-points-symbols-1.png" title="" alt="" width="288" /></p>
<p><strong>Point symbols</strong> can be changed using the argument <strong>pch</strong>.</p>
<pre class="r"><code>x<-c(2.2, 3, 3.8, 4.5, 7, 8.5, 6.7, 5.5)
y<-c(4, 5.5, 4.5, 9, 11, 15.2, 13.3, 10.5)
# Change plotting symbol using pch
plot(x, y, pch = 19, col="blue")
plot(x, y, pch = 18, col="red")
plot(x, y, pch = 24, cex=2, col="blue", bg="red", lwd=2)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-change-plotting-pch-symbols-1.png" title="" alt="" width="108" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-change-plotting-pch-symbols-2.png" title="" alt="" width="108" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-change-plotting-pch-symbols-3.png" title="" alt="" width="108" /></p>
<p><span class="success"><i class="fa fa-plus-circle"></i> Read more —> <a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">R plot pch symbols : The different point shapes available in R</a>.</span></p>
</div>
<div id="change-line-types" class="section level1">
<h1>Change line types</h1>
<p>The following <strong>line types</strong> are available in R :</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-available-line-types-1.png" title="" alt="" width="288" /></p>
<p><strong>Line types</strong> can be changed using the graphical parameter <strong>lty</strong>.</p>
<pre class="r"><code>x=1:10; y=x*x
plot(x, y, type="l") # Solid line (by default)
plot(x, y, type="l", lty="dashed")# Use dashed line type
plot(x, y, type="l", lty="dashed", lwd=3)# Change line width</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-change-line-types-1.png" title="" alt="" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-change-line-types-2.png" title="" alt="" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-change-line-types-3.png" title="" alt="" width="144" /></p>
<p><span class="success"><i class="fa fa-plus-circle"></i> Read more —> <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">Line types in R : lty</a>.</span></p>
</div>
<div id="change-colors" class="section level1">
<h1>Change colors</h1>
<ul>
<li>Built-in color names in R</li>
<li>Specifying colors by hexadecimal code</li>
<li>Using RColorBrewer palettes</li>
<li>Use Wes Anderson color palettes</li>
<li>Create a vector of n contiguous colors</li>
</ul>
<p>Colors can be specified by names (e.g <strong>col=red</strong>) or with hexadecimal code (e.g<strong>col = “#FFCC00”</strong>).</p>
<pre class="r"><code># use color names
barplot(c(2,5), col=c("blue", "red"))
# use hexadecimal color code
barplot(c(2,5), col=c("#009999", "#0000FF"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-change-colors-1.png" title="" alt="" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-graphical-parameters-change-colors-2.png" title="" alt="" width="144" /></p>
<p><strong>Hexadecimal color charts :</strong></p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/images/hextable.gif" alt="Hexadecimal color code" />
(Source: <a href="http://www.visibone.com" class="uri">http://www.visibone.com</a>)</p>
<p><strong>RColorBrewer</strong> package can also be used to create a nice looking color palettes. Read our article : <a href="https://www.sthda.com/english/english/wiki/colors-in-r">Colors in R</a>.</p>
<p><span class="success"><i class="fa fa-plus-circle"></i> Read more —> <a href="https://www.sthda.com/english/english/wiki/colors-in-r">Colors in R</a>.</span></p>
</div>
<div id="related-articles" class="section level1">
<h1>Related articles</h1>
<p><span class="success"> Click on the following articles to read more.</span></p>
<p><br/></p>
<div class="small-block">
<h1>
<a href="https://www.sthda.com/english/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r">Plotting symbols in R</a>
</h1>
<img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-plot-pch-symbols-points-in-r.png" alt="plotting symbols" />
 Different <strong>plotting symbols</strong> are available in R. The <strong>graphical argument</strong> used to specify point shapes is <strong>pch</strong>.

</div>
<div class="small-block">
<h1>
<a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">Line types in R</a>
</h1>
<img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/linetypes-in-r-line-types.png" alt="Line types" />
 The argument <strong>lty</strong> can be used to specify the <strong>line type</strong>. To change <strong>line width</strong>, the argument <strong>lwd</strong> can be used.

</div>
<div class="small-block">
<h1>
<a href="https://www.sthda.com/english/english/wiki/colors-in-r">Colors in R</a>
</h1>
<img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-built-in-color-names1.png" alt="Colors in R" />
 <strong>Colors</strong> can be specified either by <strong>name</strong> (e.g col = “red”) or as a <strong>hexadecimal</strong> code (such as col = “#FFCC00”). You can also use other color systems such as ones taken from the <strong>RColorBrewer</strong> package.

</div>
<div class="small-block">
<h1>
<a href="https://www.sthda.com/english/english/wiki/add-titles-to-a-plot-in-r-software">Add titles to a plot</a>
</h1>
<img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-title-use-par-function.png" alt="Add titles to a plot" />
 <strong>Plot titles</strong> can be specified either directly to the <strong>plotting functions</strong> during the plot creation or by using the <strong>title()</strong> function (to add titles on an existing plot).

</div>
<div class="small-block">
<h1>
<a href="https://www.sthda.com/english/english/wiki/add-legends-to-plots-in-r-software-the-easiest-way">Add legends to plots</a>
</h1>
<img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-legend-to-plot-legend-box-bacground-color.png" alt="Add titles to a plot" />
 To add <strong>legends</strong> to plots in <strong>R</strong>, the <strong>R legend()</strong> function can be used.

</div>
<div class="small-block">
<h1>
<a href="https://www.sthda.com/english/english/wiki/add-text-to-a-plot-in-r-software">Add texts to a plot</a>
</h1>
<img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-text-to-a-plot-math-expression.png" alt="Add texts to a plot" />
 To <strong>add a text</strong> to a <strong>plot</strong> in <strong>R</strong>, the <strong>text()</strong> and <strong>mtext()</strong> <strong>R</strong> functions can be used.
</div>
<div class="small-block">
<h1>
<a href="https://www.sthda.com/english/english/wiki/abline-r-function-an-easy-way-to-add-straight-lines-to-a-plot-using-r-software">Add straight lines</a>
</h1>
<img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/abline-add-straight-lines-to-a-plot-example.png" alt="Add straight lines" />
 The R function <strong>abline()</strong> can be used to add <strong>vertical</strong>, <strong>horizontal</strong> or <strong>regression</strong> <strong>lines</strong> to a graph.
</div>
<div class="small-block">
<h1>
<a href="https://www.sthda.com/english/english/wiki/add-an-axis-to-a-plot-with-r-software">Add an axis to a plot</a>
</h1>
<img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-axis-to-plots-example2.png" alt="Add an axis to a plot" />
 <strong>axis()</strong> function can be used to add a <strong>secondary axis</strong> to a plot.
</div>
<div class="small-block">
<h1>
<a href="https://www.sthda.com/english/english/wiki/axis-scale-in-r-software-minimum-maximum-and-log-scale">Change axis scale in R</a>
</h1>
<img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/axis-scale-exemple3.png" alt="Change axis scale in R" />
 The goal of this article is to show you how to set <strong>x and y axis limites</strong> by specifying the minimum and the maximum values of each axis. We’ll also see how to set the <strong>log scale</strong>.
</div>
<style>
  .small-block{width:250px; padding : 2px; margin-right:5px}
  .small-block img{width:220px;}
</style>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.2.4). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->

<!-- END HTML -->]]></description>
			<pubDate>Sat, 07 May 2016 10:56:59 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Add an axis to a plot with R software]]></title>
			<link>https://www.sthda.com/english/wiki/add-an-axis-to-a-plot-with-r-software</link>
			<guid>https://www.sthda.com/english/wiki/add-an-axis-to-a-plot-with-r-software</guid>
			<description><![CDATA[<!-- START HTML -->

            
  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">
<p>The goal of this article is to show you how to add <strong>axis</strong> to a plot using <strong>R software</strong>. For this end, we’ll use the <strong>R axis()</strong> function. A simplified format of this function is :</p>
<pre class="r"><code>axis(side, at=NULL, labels=TRUE)</code></pre>
<br/>
<div class="block">
<ul>
<li><strong>side</strong> : an integer indicating which side of the plot the axis is to be drawn on; Possible values are :
<ul>
<li><strong>1</strong>: below</li>
<li><strong>2</strong>: left</li>
<li><strong>3</strong>: above</li>
<li><strong>4</strong>: right</li>
</ul></li>
<li><strong>at</strong>: The points at which tick-marks are to be drawn.</li>
<li><strong>labels</strong>: Texts for tick-mark labels. It can also be logical specifying whether annotations are to be made at the tick-marks.</li>
</ul>
</div>
<p><br/></p>
<p>Example :</p>
<pre class="r"><code>x<-1:4; y=x*x
# Example 1
plot(x, y, axes = FALSE)
axis(side=1, at = 1:4, labels=LETTERS[1:4])
axis(2)

# Example 2
plot(x, y, axes = FALSE)
axis(side=1, at=1:4, labels=LETTERS[1:4])
axis(2)
box() #- To make it look like "usual" plot</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-axis-to-plots-example11.png" title="R axis : Tutorial on how to set axis in R" alt="R axis : Tutorial on how to set axis in R" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-axis-to-plots-example12.png" title="R axis : Tutorial on how to set axis in R" alt="R axis : Tutorial on how to set axis in R" width="240" /></p>

<p>Another example is :</p>
<pre class="r"><code>plot(x, y, pch=18, col="red", type="b",
     frame=FALSE, xaxt="n") # Remove x axis
axis(1, 1:4, LETTERS[1:4], col.axis="blue")
axis(3, col = "darkgreen", lty = 2, lwd = 0.5)
axis(4, col = "violet", col.axis = "dark violet", lwd = 2)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-axis-to-plots-example2.png" title="R axis : Tutorial on how to set axis in R" alt="R axis : Tutorial on how to set axis in R" width="240" /></p>
<p><span class="success">Note that <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">lty</a> and <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">lwd</a> specify line-type and line-width, respectively. </span></p>
<p><strong>Infos</strong></p>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.1.0). </span></p>

<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:23:30 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Add legends to plots in R software : the easiest way!]]></title>
			<link>https://www.sthda.com/english/wiki/add-legends-to-plots-in-r-software-the-easiest-way</link>
			<guid>https://www.sthda.com/english/wiki/add-legends-to-plots-in-r-software-the-easiest-way</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#r-legend-function">R legend function</a></li>
<li><a href="#title-text-font-and-background-color-of-the-legend-box">Title, text font and background color of the legend box</a></li>
<li><a href="#border-of-the-legend-box">Border of the legend box</a></li>
<li><a href="#specify-legend-position-by-keywords">Specify legend position by keywords</a><ul>
<li><a href="#example-1-line-plot">Example 1: line plot</a></li>
<li><a href="#example-2-box-plot">Example 2: box plot</a></li>
</ul></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>The goal of this article is to show you how to add <strong>legends</strong> to plots using <strong>R statistical software</strong>.</p>
<div id="r-legend-function" class="section level1">
<h1>R legend function</h1>
<p>To add <strong>legends</strong> to plots in <strong>R</strong>, the <strong>R legend()</strong> function can be used. A simplified format of the function is :</p>
<pre class="r"><code>legend(x, y=NULL, legend, fill, col, bg)</code></pre>
<br/>
<div class="block">
<ul>
<li><strong>x and y</strong> : the x and y co-ordinates to be used to position the legend</li>
<li><strong>legend</strong> : the text of the legend</li>
<li><strong>fill</strong> : colors to use for filling the boxes beside the legend text</li>
<li><strong>col</strong> : colors of lines and points beside the legend text</li>
<li><strong>bg</strong> : the background color for the legend box.</li>
</ul>
</div>
<p><br/></p>

<p>Example :</p>
<pre class="r"><code># Generate some data
x<-1:10; y1=x*x; y2=2*y1

plot(x, y1, type="b", pch=19, col="red", xlab="x", ylab="y")
# Add a line
lines(x, y2, pch=18, col="blue", type="b", lty=2)
# Add a legend
legend(1, 95, legend=c("Line 1", "Line 2"),
       col=c("red", "blue"), lty=1:2, cex=0.8)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-legend-to-plot-example.png" title="R legend : tutorial on how add legends to plots using R software" alt="R legend : tutorial on how add legends to plots using R software" width="268.8" /></p>
<p>To avoid repeating the above <strong>R</strong> code, we can create a custom plot function as follow :</p>
<pre class="r"><code>makePlot<-function(){
  x<-1:10; y1=x*x; y2=2*y1
  plot(x, y1, type="b", pch=19, col="red", xlab="x", ylab="y")
  lines(x, y2, pch=18, col="blue", type="b", lty=2)
}</code></pre>
</div>
<div id="title-text-font-and-background-color-of-the-legend-box" class="section level1">
<h1>Title, text font and background color of the legend box</h1>
<p>The arguments below can be used :</p>
<ul>
<li><strong>title</strong>: The title of the legend</li>
<li><strong>text.font</strong>: an integer specifying the font style of the legend text; possible values are :
<ul>
<li><strong>1</strong>: normal</li>
<li><strong>2</strong>: bold</li>
<li><strong>3</strong>: italic</li>
<li><strong>4</strong>: bold and italic</li>
</ul></li>
<li><strong>bg</strong>: background color of the legend box</li>
</ul>
<pre class="r"><code>makePlot()
# Add a legend to the plot
legend(1, 95, legend=c("Line 1", "Line 2"),
       col=c("red", "blue"), lty=1:2, cex=0.8,
       title="Line types", text.font=4, bg=&amp;#39;lightblue&amp;#39;)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-legend-to-plot-legend-box-bacground-color.png" title="R legend : tutorial on how add legends to plots using R software" alt="R legend : tutorial on how add legends to plots using R software" width="268.8" /></p>
</div>
<div id="border-of-the-legend-box" class="section level1">
<h1>Border of the legend box</h1>
<p>The arguments <strong>box.lty, box.lwd and box.col</strong> can be used to modify the line type, width and color for the legend box border, respectively.</p>
<pre class="r"><code># Remove legend border using box.lty = 0
makePlot()
legend(1, 95, legend=c("Line 1", "Line 2"),
       col=c("red", "blue"), lty=1:2, cex=0.8,
       box.lty=0)

# Change the border
makePlot()
legend(1, 95, legend=c("Line 1", "Line 2"),
       col=c("red", "blue"), lty=1:2, cex=0.8,
       box.lty=2, box.lwd=2, box.col="green")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-legend-to-plot-legend-box-border1.png" title="R legend : tutorial on how add legends to plots using R software" alt="R legend : tutorial on how add legends to plots using R software" width="268.8" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-legend-to-plot-legend-box-border2.png" title="R legend : tutorial on how add legends to plots using R software" alt="R legend : tutorial on how add legends to plots using R software" width="268.8" /></p>
</div>
<div id="specify-legend-position-by-keywords" class="section level1">
<h1>Specify legend position by keywords</h1>
<p>The position of the legend can be specified also using the following keywords : <code>"bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right" and "center".</code></p>
<p>The effect of using each of these keywords are shown in the figure below :</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-legend-to-plot-legend-positions.png" title="R legend : tutorial on how add legends to plots using R software" alt="R legend : tutorial on how add legends to plots using R software" width="384" /></p>
<div id="example-1-line-plot" class="section level2">
<h2>Example 1: line plot</h2>
<pre class="r"><code>#  Example 1: line plot
makePlot()
legend("topleft", legend=c("Line 1", "Line 2"),
       col=c("red", "blue"), lty=1:2, cex=0.8)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-legend-to-plot-position.png" title="R legend : tutorial on how add legends to plots using R software" alt="R legend : tutorial on how add legends to plots using R software" width="268.8" /></p>
</div>
<div id="example-2-box-plot" class="section level2">
<h2>Example 2: box plot</h2>
<pre class="r"><code>attach(mtcars)
boxplot(mpg~cyl, 
        xlab="Cylinders", ylab="Miles/(US) gallon", 
        col=topo.colors(3))
   
legend("bottomleft", inset=.02, title="Number of Cylinders",
   c("4","6","8"), fill=topo.colors(3), horiz=TRUE, cex=0.8)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-legend-to-plot-boxplot.png" title="R legend : tutorial on how add legends to plots using R software" alt="R legend : tutorial on how add legends to plots using R software" width="288" /></p>
<p><span class="success">Note that the argument <code>fill</code> indicates the colors to use for filling the boxes beside the legend text</span></p>
</div>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.1.0). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->


<!-- END HTML -->]]></description>
			<pubDate>Fri, 06 Feb 2015 21:20:25 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[abline R function : An easy way to add straight lines to a plot using R software]]></title>
			<link>https://www.sthda.com/english/wiki/abline-r-function-an-easy-way-to-add-straight-lines-to-a-plot-using-r-software</link>
			<guid>https://www.sthda.com/english/wiki/abline-r-function-an-easy-way-to-add-straight-lines-to-a-plot-using-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="#add-a-vertical-line">Add a vertical line</a></li>
<li><a href="#add-an-horizontal-line">Add an horizontal line</a></li>
<li><a href="#add-regression-line">Add regression line</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>The aim of this tutorial is to show you how to add one or more <strong>straight lines</strong> to a <strong>graph</strong> using <strong>R statistical software</strong>. The R function <strong>abline()</strong> can be used to add <strong>vertical</strong>, <strong>horizontal</strong> or <strong>regression</strong> <strong>lines</strong> to a graph.</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/abline-add-straight-lines-to-a-plot-example.png" title="How to add straight lines to a plot using R statistical software" alt="How to add straight lines to a plot using R statistical software" width="288" /></p>
<p>A simplified format of the <strong>abline()</strong> function is :</p>
<pre class="r"><code>abline(a=NULL, b=NULL, h=NULL, v=NULL, ...)</code></pre>
<br/>
<div class="block">
<ul>
<li><strong>a, b</strong> : single values specifying the <strong>intercept</strong> and the <strong>slope</strong> of the line</li>
<li><strong>h</strong> : the <strong>y-value(s)</strong> for horizontal line(s)</li>
<li><strong>v</strong> : the <strong>x-value(s)</strong> for vertical line(s)</li>
</ul>
</div>
<p><br/></p>
<div id="add-a-vertical-line" class="section level1">
<h1>Add a vertical line</h1>
<p>The simplified format is :</p>
<pre class="r"><code>abline(v = y)</code></pre>
<p>It draws a vertical line on the current plot at the specified ‘y’ coordinates.</p>
<pre class="r"><code># first example : Add one line
plot(cars)
abline(v=15, col="blue")

# second example : add 2 lines 
# change line colors, sizes and types
plot(cars)
abline(v=c(15,20), col=c("blue", "red"), lty=c(1,2), lwd=c(1, 3))

# third example
set.seed(1234); mydata<-rnorm(200)
hist(mydata, col="lightblue")
abline(v = mean(mydata), col="red", lwd=3, lty=2)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/abline-add-straight-lines-to-a-plot-vertical-line1.png" title="How to add straight lines to a plot using R statistical software" alt="How to add straight lines to a plot using R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/abline-add-straight-lines-to-a-plot-vertical-line2.png" title="How to add straight lines to a plot using R statistical software" alt="How to add straight lines to a plot using R statistical software" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/abline-add-straight-lines-to-a-plot-vertical-line3.png" title="How to add straight lines to a plot using R statistical software" alt="How to add straight lines to a plot using R statistical software" width="240" /></p>
<p><span class="success">Note that, <strong>line types</strong> (<code>lty</code>) and <strong>line width</strong> (<code>lwd</code>) are explained <a href="https://www.sthda.com/english/english/wiki/line-types-in-r-lty">here</a>.</span></p>
</div>
<div id="add-an-horizontal-line" class="section level1">
<h1>Add an horizontal line</h1>
<p>The simplified format is :</p>
<pre class="r"><code>abline(h = x)</code></pre>
<p>It draws an horizontal line on the current plot at the specified ‘x’ coordinates.</p>
<pre class="r"><code>plot(cars)
abline(h=40, col="blue")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/abline-add-straight-lines-to-a-plot-horizontal-line.png" title="How to add straight lines to a plot using R statistical software" alt="How to add straight lines to a plot using R statistical software" width="240" /></p>
</div>
<div id="add-regression-line" class="section level1">
<h1>Add regression line</h1>
<p><strong>lm()</strong> function is used to fit linear models.</p>
<pre class="r"><code>par(mgp=c(2,1,0), mar=c(3,3,1,1))
# Fit regression line
require(stats)
reg<-lm(dist ~ speed, data = cars)
coeff=coefficients(reg)
# equation of the line : 
eq = paste0("y = ", round(coeff[2],1), "*x ", round(coeff[1],1))
# plot
plot(cars, main=eq)
abline(reg, col="blue")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/abline-add-straight-lines-to-a-plot-regresion-line.png" title="How to add straight lines to a plot using R statistical software" alt="How to add straight lines to a plot using R statistical software" width="240" /></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.1.0). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->

<!-- END HTML -->]]></description>
			<pubDate>Mon, 26 Jan 2015 22:07:03 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Colors in R]]></title>
			<link>https://www.sthda.com/english/wiki/colors-in-r</link>
			<guid>https://www.sthda.com/english/wiki/colors-in-r</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#built-in-color-names-in-r">Built-in color names in R</a></li>
<li><a href="#specifying-colors-by-hexadecimal-code">Specifying colors by hexadecimal code</a></li>
<li><a href="#using-rcolorbrewer-palettes">Using RColorBrewer palettes</a></li>
<li><a href="#use-wes-anderson-color-palettes">Use Wes Anderson color palettes</a></li>
<li><a href="#create-a-vector-of-n-contiguous-colors">Create a vector of n contiguous colors</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>In <strong>R</strong>, <strong>colors</strong> can be specified either by name (e.g <strong>col = “red”</strong>) or as a hexadecimal RGB triplet (such as <strong>col = “#FFCC00”</strong>). You can also use other <strong>color</strong> systems such as ones taken from the <strong>RColorBrewer package</strong>.</p>
<div id="built-in-color-names-in-r" class="section level1">
<h1>Built-in color names in R</h1>
<p>We will use the following custom R function to generate a plot of color names available in R :</p>
<pre class="r"><code># Generate a plot of color names which R knows about.
#++++++++++++++++++++++++++++++++++++++++++++
# cl : a vector of colors to plots
# bg: background of the plot
# rot: text rotation angle

#usage=showCols(bg="gray33")
showCols <- function(cl=colors(), bg = "grey",
                     cex = 0.75, rot = 30) {
    m <- ceiling(sqrt(n <-length(cl)))
    length(cl) <- m*m; cm <- matrix(cl, m)
    require("grid")
    grid.newpage(); vp <- viewport(w = .92, h = .92)
    grid.rect(gp=gpar(fill=bg))
    grid.text(cm, x = col(cm)/m, y = rev(row(cm))/m, rot = rot,
              vp=vp, gp=gpar(cex = cex, col = cm))
  }</code></pre>
<p>The names of the first sixty colors are shown in the following chart :</p>
<pre class="r"><code># The first sixty color names
showCols(bg="gray20",cl=colors()[1:60], rot=30, cex=0.9)

# Barplot using color names
barplot(c(2,5), col=c("chartreuse", "blue4"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-built-in-color-names1.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="240" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-built-in-color-names2.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="240" /></p>
<div class="warning">
<p>To view all the built-in color names which R knows about (n = 657), use the following <strong>R</strong> code :</p>
<pre class="r"><code>showCols(cl= colors(), bg="gray33", rot=30, cex=0.75)</code></pre>
</div>
</div>
<div id="specifying-colors-by-hexadecimal-code" class="section level1">
<h1>Specifying colors by hexadecimal code</h1>
<p><span class="success">Colors can be specified using hexadecimal color code, such as <strong>“#FFC00”</strong></span></p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/images/hextable.gif" alt="Hexadecimal color code" />
(Source: <a href="http://www.visibone.com">http://www.visibone.com</a>)</p>
<pre class="r"><code># Barplot using hexadecimal color code
barplot(c(2,5), col=c("#009999", "#0000FF"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-hexadecimal-color-code.png" title="hexadecimal color code" alt="hexadecimal color code" width="134.4" /></p>
</div>
<div id="using-rcolorbrewer-palettes" class="section level1">
<h1>Using RColorBrewer palettes</h1>
<p>You have to install the <strong>RColorBrewer</strong> package as follow :</p>
<pre class="r"><code>install.packages("RColorBrewer")</code></pre>
<p><span class="success"><strong>RColorBrewer</strong> package create a nice looking color palettes. </span></p>
<p>The color palettes associated to <strong>RColorBrewer</strong> package can be drawn using <strong>display.brewer.all()</strong> R function as follow :</p>
<pre class="r"><code>library("RColorBrewer")
display.brewer.all()</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-rcolorbrewer-palettes.png" title="Rcolorbrewer palettes" alt="Rcolorbrewer palettes" width="336" /></p>
<br/>
<div class="block">
<p>There are <strong>3 types of palettes</strong> : sequential, diverging, and qualitative.</p>
<ol style="list-style-type: decimal">
<li><strong>Sequential palettes</strong> are suited to ordered data that progress from low to high (gradient). The palettes names are : Blues, BuGn, BuPu, GnBu, Greens, Greys, Oranges, OrRd, PuBu, PuBuGn, PuRd, Purples, RdPu, Reds, YlGn, YlGnBu YlOrBr, YlOrRd.</li>
<li><strong>Diverging palettes</strong> put equal emphasis on mid-range critical values and extremes at both ends of the data range. The diverging palettes are : BrBG, PiYG, PRGn, PuOr, RdBu, RdGy, RdYlBu, RdYlGn, Spectral</li>
<li><strong>Qualitative palettes</strong> are best suited to representing nominal or categorical data. They not imply magnitude differences between groups. The palettes names are : Accent, Dark2, Paired, Pastel1, Pastel2, Set1, Set2, Set3</li>
</ol>
</div>
<p><br/></p>
<p>You can also view a single RColorBrewer palette by specifying its name as follow :</p>
<pre class="r"><code># View a single RColorBrewer palette by specifying its name
display.brewer.pal(n = 8, name = &amp;#39;RdBu&amp;#39;)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-display-rcolorbrewer-single-palette.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="192" /></p>
<pre class="r"><code># Hexadecimal color specification 
brewer.pal(n = 8, name = "RdBu")</code></pre>
<pre><code>## [1] "#B2182B" "#D6604D" "#F4A582" "#FDDBC7" "#D1E5F0" "#92C5DE" "#4393C3" "#2166AC"</code></pre>
<pre class="r"><code># Barplot using RColorBrewer
barplot(c(2,5,7), col=brewer.pal(n = 3, name = "RdBu"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-plot-wusing-rcolorbrewer-palette.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="134.4" /></p>
</div>
<div id="use-wes-anderson-color-palettes" class="section level1">
<h1>Use Wes Anderson color palettes</h1>
<p>This color palettes can be installed and loaded as follow :</p>
<pre class="r"><code># Install
install.packages("wesanderson")

# Load
library(wesanderson)</code></pre>
<p>The available color palettes are :</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-wesanderson-palettes1.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-wesanderson-palettes2.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-wesanderson-palettes3.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-wesanderson-palettes4.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-wesanderson-palettes5.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-wesanderson-palettes6.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-wesanderson-palettes7.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-wesanderson-palettes8.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-wesanderson-palettes9.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-wesanderson-palettes10.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-wesanderson-palettes11.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-wesanderson-palettes12.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-wesanderson-palettes13.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="144" /></p>
<p>Use the palettes as follow :</p>
<pre class="r"><code># simple barplot
barplot(c(2,5,7), col=wes.palette(n=3, name="GrandBudapest"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-grandbudapest-barplot.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="192" /></p>
<pre class="r"><code>library(ggplot2)
ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + 
  geom_point(size = 2) + 
  scale_color_manual(values = wes.palette(n=3, name="GrandBudapest"))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-grandbudapest-ggplot2.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="384" /></p>
</div>
<div id="create-a-vector-of-n-contiguous-colors" class="section level1">
<h1>Create a vector of n contiguous colors</h1>
<p>You can also generate a vector of n contiguous colors using the functions <strong>rainbow(n)</strong>, <strong>heat.colors(n)</strong>, <strong>terrain.colors(n)</strong>, <strong>topo.colors(n)</strong>, and <strong>cm.colors(n)</strong>.</p>
<pre class="r"><code># Use rainbow colors
barplot(1:5, col=rainbow(5))
# Use heat.colors
barplot(1:5, col=heat.colors(5))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-contiguous-colors1.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="134.4" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-contiguous-colors2.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="134.4" /></p>
<pre class="r"><code># Use terrain.colors
barplot(1:5, col=terrain.colors(5))
# Use topo.colors
barplot(1:5, col=topo.colors(5))
# Use cm.colors
barplot(1:5, col=cm.colors(5))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-contiguous-colors-terrain-topo1.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="134.4" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-contiguous-colors-terrain-topo2.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="134.4" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/colors-in-r-contiguous-colors-terrain-topo3.png" title="Colors in r : tutorial on available R colors for plotting" alt="Colors in r : tutorial on available R colors for plotting" width="134.4" /></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<pre class="warning"><code>This analysis has been performed using R (ver. 3.1.0).</code></pre>
<p><br/></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->


<!-- END HTML -->]]></description>
			<pubDate>Mon, 19 Jan 2015 21:08:15 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Add titles to a plot in R software]]></title>
			<link>https://www.sthda.com/english/wiki/add-titles-to-a-plot-in-r-software</link>
			<guid>https://www.sthda.com/english/wiki/add-titles-to-a-plot-in-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="#change-main-title-and-axis-labels">Change main title and axis labels</a></li>
<li><a href="#title-colors">title colors</a></li>
<li><a href="#the-font-style-for-the-text-of-the-titles">The font style for the text of the titles</a></li>
<li><a href="#change-the-font-size">Change the font size</a></li>
<li><a href="#use-the-title-function">Use the title() function</a></li>
<li><a href="#customize-the-titles-using-par-function">Customize the titles using par() function</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>The aim of this article is to show how to <strong>modify</strong> the <strong>title of graphs</strong> (main title and axis titles) in <strong>R software</strong>. There are two possible ways to do that :</p>
<ul>
<li>Directly by specifying the titles to the plotting function (ex : <code>plot()</code> ). In this case titles are modified during the creation of plot.</li>
<li>the <strong>title()</strong> function can also be used. It adds <strong>titles</strong> on an existing plot.</li>
</ul>
<div id="change-main-title-and-axis-labels" class="section level1">
<h1>Change main title and axis labels</h1>
<p>The following arguments can be used :</p>
<div class="block">
<ul>
<li><strong>main</strong>: the text for the <strong>main title</strong></li>
<li><strong>xlab</strong>: the text for the <strong>x axis label</strong></li>
<li><strong>ylab</strong>: the text for <strong>y axis title</strong></li>
<li><strong>sub</strong>: <strong>sub-title</strong>; It’s placed at the bottom of x-axis
</li>
</ul>
</div>
<pre class="r"><code># Simple graph
barplot(c(2,5))
# Add titles
barplot(c(2,5), main="Main title",
        xlab="X axis title",
        ylab="Y axis title",
        sub="Sub-title")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-title-change-title1.png" title="Plot title in R" alt="Plot title in R" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-title-change-title2.png" title="Plot title in R" alt="Plot title in R" width="144" /></p>
</div>
<div id="title-colors" class="section level1">
<h1>title colors</h1>
<p>The following parameters can be used to change the <strong>colors</strong> :</p>
<ul>
<li><strong>col.main</strong>: color the main title</li>
<li><strong>col.lab</strong>: color of the axis titles (x and y axis)</li>
<li><strong>col.sub</strong>: color of the sub-title</li>
</ul>
<pre class="r"><code>barplot(c(2,5), main="Main title",
        xlab="X axis title",
        ylab="Y axis title",
        sub="Sub-title",
        col.main="red", col.lab="blue", col.sub="black")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-title-change-color.png" title="Plot title in R" alt="Plot title in R" width="144" /></p>
<p><span class="warning">Note that, the different colors available in <strong>R software</strong> are described <a href="https://www.sthda.com/english/english/wiki/colors-in-r">here</a>.</span></p>
</div>
<div id="the-font-style-for-the-text-of-the-titles" class="section level1">
<h1>The font style for the text of the titles</h1>
<p>The <strong>graphical parameters</strong> to use for customizing the font of the titles are :</p>
<ul>
<li><strong>font.main</strong>: font style for the main title</li>
<li><strong>font.lab</strong>: font style for the axis titles</li>
<li><strong>font.sub</strong>: font style for the sub-title</li>
</ul>
<p>The value of these arguments should be an integer.</p>
<div class="success">
<p>The possible values for the <strong>font style</strong> are :</p>
<ul>
<li><strong>1</strong>: normal text</li>
<li><strong>2</strong>: bold</li>
<li><strong>3</strong>: italic</li>
<li><strong>4</strong>: bold and italic</li>
<li><strong>5</strong> : Symbol font
</li>
</ul>
</div>
<p>Use the <strong>R code</strong> below to create a <strong>plot title</strong> with bold and italic font style.</p>
<pre class="r"><code># Titles in bold and italic
barplot(c(2,5), main="Main title",
        xlab="X axis title",
        ylab="Y axis title",
        sub="Sub-title",
        font.main=4, font.lab=4, font.sub=4)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-title-change-font.png" title="Plot title in R" alt="Plot title in R" width="144" /></p>
</div>
<div id="change-the-font-size" class="section level1">
<h1>Change the font size</h1>
<p><strong>font size</strong> can be modified using the <strong>graphical parameter</strong> : <strong>cex</strong>. The default value is 1. If <strong>cex</strong> value is inferior to 1, then the text size is decreased. Conversely, any value of <strong>cex</strong> greater than 1 can increase the font size.</p>
<p>The following arguments can be used to change the <strong>font size</strong> :</p>
<ul>
<li><strong>cex.main</strong> : text size for main title</li>
<li><strong>cex.lab</strong> : text size for axis title</li>
<li><strong>cex.sub</strong> : text size of the sub-title</li>
</ul>
<p>An example is shown below :</p>
<pre class="r"><code># Increase the size
barplot(c(2,5), main="Main title",
        xlab="X axis title",
        ylab="Y axis title",
        sub="Sub-title",
        cex.main=2, cex.lab=1.7, cex.sub=1.2)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-title-change-font-size.png" title="Plot title in R" alt="Plot title in R" width="288" /></p>
</div>
<div id="use-the-title-function" class="section level1">
<h1>Use the title() function</h1>
<p><strong>title()</strong> can be also used to add titles to a graph.</p>
<p>A simplified format is :</p>
<pre class="r"><code>title(main = NULL, sub = NULL, 
      xlab = NULL, ylab = NULL, ...)</code></pre>
<p>Example of usage</p>
<pre class="r"><code>x<-1:10; y<-x*x
plot(x,y, main = "", xlab="", ylab="",
     col.axis="blue") 
title(main = "Main title", sub = "Sub-title",
      xlab = "X axis", ylab = "Y axis",
      cex.main = 2,   font.main= 4, col.main= "red",
      cex.sub = 0.75, font.sub = 3, col.sub = "green",
      col.lab ="darkblue"
      )</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-title-using-title-function.png" title="Plot title in R" alt="Plot title in R" width="288" /></p>
</div>
<div id="customize-the-titles-using-par-function" class="section level1">
<h1>Customize the titles using par() function</h1>
<p>Note that, the <strong>R par()</strong> function can be used to change the <strong>color</strong>, <strong>font style and size</strong> for the graph titles. The modifications done by the <strong>par()</strong> function are called ‘permanent modification’ because they are applied to all the plots generated under the current R session.</p>
<p>Read more on par() by clicking <a href="https://www.sthda.com/english/english/wiki/graphical-parameters">here</a>.</p>
<pre class="r"><code>par(
  # Change the colors
  col.main="red", col.lab="blue", col.sub="black",
  # Titles in italic and bold
  font.main=4, font.lab=4, font.sub=4,
  # Change font size
  cex.main=2, cex.lab=1.7, cex.sub=1.2
  )

barplot(c(2,5), main="TMain title",
        xlab="X axis title",
        ylab="Y axis title",
        sub="Sub title")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-title-use-par-function.png" title="Plot title in R" alt="Plot title in R" width="288" /></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.1.0). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->



<!-- END HTML -->]]></description>
			<pubDate>Tue, 13 Jan 2015 07:07:04 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Axis scale in R software : minimum, maximum and log scale]]></title>
			<link>https://www.sthda.com/english/wiki/axis-scale-in-r-software-minimum-maximum-and-log-scale</link>
			<guid>https://www.sthda.com/english/wiki/axis-scale-in-r-software-minimum-maximum-and-log-scale</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">

<div id="TOC">
<ul>
<li><a href="#arguments">Arguments</a></li>
<li><a href="#examples">Examples</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>The goal of this article is to show you how to set <strong>x and y axis limites</strong> by specifying the minimum and the maximum values of each axis. We’ll also see in this this tutorial how to set the <strong>log scale</strong>.</p>
<div id="arguments" class="section level1">
<h1>Arguments</h1>
<p>The following <strong>plot parameters</strong> can be used :</p>
<ul>
<li><strong>xlim</strong>: the limit of x axis; format : <strong>xlim = c(min, max)</strong></li>
<li><strong>ylim</strong>: the limit of y axis; format: <strong>ylim = c(min, max)</strong></li>
</ul>
<p><strong>Transformation to log scale</strong>:</p>
<ul>
<li><strong>log = “x”</strong></li>
<li><strong>log = “y”</strong></li>
<li><strong>log = “xy”</strong>*</li>
</ul>
<p><strong>log</strong> : character indicating if x or y or both coordinates should be plotted in log scale.</p>
</div>
<div id="examples" class="section level1">
<h1>Examples</h1>
<pre class="r"><code>x<-1:10; y=x*x

# Simple graph
plot(x, y)

# Enlarge the scale
plot(x, y, xlim=c(1,15), ylim=c(1,150))

# Log scale
plot(x, y, log="y")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/axis-scale-exemple1.png" title="Logiciel R : Echelle des axes" alt="Logiciel R : Echelle des axes" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/axis-scale-exemple2.png" title="Logiciel R : Echelle des axes" alt="Logiciel R : Echelle des axes" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/axis-scale-exemple3.png" title="Logiciel R : Echelle des axes" alt="Logiciel R : Echelle des axes" width="144" /></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.1.0). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->



<!-- END HTML -->]]></description>
			<pubDate>Tue, 09 Dec 2014 07:04:17 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Add custom tick mark labels to a plot in R software]]></title>
			<link>https://www.sthda.com/english/wiki/add-custom-tick-mark-labels-to-a-plot-in-r-software</link>
			<guid>https://www.sthda.com/english/wiki/add-custom-tick-mark-labels-to-a-plot-in-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="#color-font-style-and-font-size-of-tick-mark-labels">Color, font style and font size of tick mark labels :</a></li>
<li><a href="#orientation-of-tick-mark-labels">Orientation of tick mark labels</a></li>
<li><a href="#hide-tick-marks">Hide tick marks</a></li>
<li><a href="#change-the-string-rotation-of-tick-mark-labels">Change the string rotation of tick mark labels</a></li>
<li><a href="#use-the-par-function">Use the par() function</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>In this article you will learn how to customize <strong>tick marks</strong> using <strong>R statistical software</strong> : changing the interval between tick marks; <strong>color</strong> and the <strong>font size</strong> for tick mark labels (texts); <strong>rotation</strong> of tick mark labels.</p>
<div id="color-font-style-and-font-size-of-tick-mark-labels" class="section level1">
<h1>Color, font style and font size of tick mark labels :</h1>
<p>For this end, the following argument can be used :</p>
<ul>
<li><strong>col.axis</strong> : the color to be used for tick mark labels</li>
<li><strong>font.axis</strong> : an integer specifying the font style; possible values are :
<ul>
<li><strong>1</strong>: normal text</li>
<li><strong>2</strong>: bold</li>
<li><strong>3</strong>: italic</li>
<li><strong>4</strong>: bold and italic</li>
<li><strong>5</strong> : symbol font
</li>
</ul></li>
<li><strong>cex.axis</strong> : the size for tick mark labels; default value is 1.</li>
</ul>
<pre class="r"><code>x<-1:10; y<-x*x
# Simple graph
plot(x, y)
# Custom plot : blue text, italic-bold, magnification
plot(x,y, col.axis="blue", font.axis=4, cex.axis=1.5)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-axis-ticks-color-font-size1.png" title="How to add tick marks to a plot wit R software" alt="How to add tick marks to a plot wit R software" width="192" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-axis-ticks-color-font-size2.png" title="How to add tick marks to a plot wit R software" alt="How to add tick marks to a plot wit R software" width="192" /></p>
</div>
<div id="orientation-of-tick-mark-labels" class="section level1">
<h1>Orientation of tick mark labels</h1>
<p>To change the style of the tick mark labels, <strong>las</strong> argument can be used. The possible values are :</p>
<ul>
<li><strong>0</strong>: the labels are parallel to the axis (default)</li>
<li><strong>1</strong>: always horizontal</li>
<li><strong>2</strong> : always perpendicular to the axis</li>
<li><strong>3</strong> : always vertical</li>
</ul>
<pre class="r"><code>plot(x, y, las=0) # parallel
plot(x, y, las=1) # horizontal
plot(x, y, las=2) # perpendicular</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-axis-ticks-orientation1.png" title="How to add tick marks to a plot wit R software" alt="How to add tick marks to a plot wit R software" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-axis-ticks-orientation2.png" title="How to add tick marks to a plot wit R software" alt="How to add tick marks to a plot wit R software" width="144" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-axis-ticks-orientation3.png" title="How to add tick marks to a plot wit R software" alt="How to add tick marks to a plot wit R software" width="144" /></p>
</div>
<div id="hide-tick-marks" class="section level1">
<h1>Hide tick marks</h1>
<p>To hide or to show tick mark labels, the following <strong>graphical parameters</strong> can be used :</p>
<ul>
<li><strong>xaxt</strong> : a character specifying the <strong>x axis</strong> type; possible values are either <strong>“s”</strong> (for showing the axis) or <strong>“n”</strong> ( for hiding the axis)</li>
<li><strong>yaxt</strong> : a character specifying the <strong>y axis</strong> type; possible values are either <strong>“s”</strong> (for showing the axis) or <strong>“n”</strong> ( for hiding the axis)</li>
</ul>
<p><span class="warning">These two arguments are very useful to take the control of the <strong>rotation angle</strong> for tick mark labels. Changing the rotation angle is not something easy in R but we’ll see how to do it in the next section.</span></p>
<pre class="r"><code># Hide x and y axis
plot(x, y, xaxt="n", yaxt="n")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-axis-ticks-hide-axis.png" title="How to add tick marks to a plot wit R software" alt="How to add tick marks to a plot wit R software" width="144" /></p>
</div>
<div id="change-the-string-rotation-of-tick-mark-labels" class="section level1">
<h1>Change the string rotation of tick mark labels</h1>
<p>The following steps can be used :</p>
<ol style="list-style-type: decimal">
<li>Hide x and y axis</li>
<li>Add tick marks using the <strong>axis()</strong> R function
</li>
<li>Add tick mark labels using the <strong>text()</strong> function</li>
</ol>
<p><span class="success">The argument <strong>srt</strong> can be used to modify the text rotation in degrees.</span></p>
<pre class="r"><code># Suppress the axis
plot(x, y, xaxt="n", yaxt="n")

# Changing x axis
xtick<-seq(0, 10, by=5)
axis(side=1, at=xtick, labels = FALSE)
text(x=xtick,  par("usr")[3], 
     labels = xtick, srt = 45, pos = 1, xpd = TRUE)

# Changing y axis
ytick<-seq(0, 100, by=50)
axis(side=2, at=ytick, labels = FALSE)
text(par("usr")[1], ytick,  
     labels = ytick, srt = 45, pos = 2, xpd = TRUE)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-axis-ticks-label-angle.png" title="How to add tick marks to a plot wit R software" alt="How to add tick marks to a plot wit R software" width="192" /></p>
</div>
<div id="use-the-par-function" class="section level1">
<h1>Use the par() function</h1>
<p>The <a href="https://www.sthda.com/english/english/wiki/graphical-parameters"><strong>par()</strong></a> function can be used to permanently apply the changes to all of the graphs that will be created in the current session.</p>
<pre class="r"><code>par(col.axis="blue", font.axis=4, cex.axis=1.5)
plot(x,y)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/graph-axis-ticks-use-par-function.png" title="How to add tick marks to a plot wit R software" alt="How to add tick marks to a plot wit R software" width="192" /></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.1.0). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->



<!-- END HTML -->]]></description>
			<pubDate>Sun, 07 Dec 2014 12:04:34 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Add text to a plot in R software]]></title>
			<link>https://www.sthda.com/english/wiki/add-text-to-a-plot-in-r-software</link>
			<guid>https://www.sthda.com/english/wiki/add-text-to-a-plot-in-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="#add-texts-within-the-graph">Add texts within the graph</a></li>
<li><a href="#add-text-in-the-margins-of-the-graph">Add text in the margins of the graph</a></li>
<li><a href="#add-mathematical-annotation-to-a-plot">Add mathematical annotation to a plot</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>To <strong>add a text</strong> to a <strong>plot</strong> in <strong>R</strong>, the <strong>text()</strong> and <strong>mtext()</strong> <strong>R</strong> functions can be used.</p>
<div id="add-texts-within-the-graph" class="section level1">
<h1>Add texts within the graph</h1>
<p>The <strong>text()</strong> function can be used to draw text inside the plotting area. A simplified format of the function is :</p>
<pre class="r"><code>text(x, y, labels)</code></pre>
<div class="success">
<ul>
<li><strong>x and y</strong>: numeric vectors specifying the coordinates of the text to plot</li>
<li><strong>labels</strong>: a character vector indicating the text to be written</li>
</ul>
</div>
<p>An example is shown below :</p>
<pre class="r"><code>d<-head(mtcars)

plot(d[,&amp;#39;wt&amp;#39;], d[,&amp;#39;mpg&amp;#39;], 
     main="Milage vs. Car Weight\n~~~~~~~~~~~~~~~~~~~",
      xlab="Weight", ylab="Miles/(US) gallon",
      pch=19, col="darkgreen")

text(d[,&amp;#39;wt&amp;#39;], d[,&amp;#39;mpg&amp;#39;],  row.names(d),
     cex=0.65, pos=3,col="red") </code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-text-to-a-plot-text-function.png" title="R software : Add a text to a plot" alt="R software : Add a text to a plot" width="240" /></p>
</div>
<div id="add-text-in-the-margins-of-the-graph" class="section level1">
<h1>Add text in the margins of the graph</h1>
<p>The <strong>mtext()</strong> R function can be used to put a text in one of the four margins of the plot. A simplified format of the function is :</p>
<pre class="r"><code>mtext(text, side=3)</code></pre>
<div class="success">
<ul>
<li><strong>text</strong> : the text to be written</li>
<li><strong>side</strong> : an integer specifying the side of the plot; Possible values are :
<ul>
<li><strong>1</strong>: bottom</li>
<li><strong>2</strong>: left</li>
<li><strong>3</strong>: top</li>
<li><strong>4</strong>: right</li>
</ul></li>
</ul>
</div>
<p>An example is shown below :</p>
<pre class="r"><code>plot(1:10, 1:10, 
     main="mtext(...) examples\n~~~~~~~~~~~")
mtext("Magic function", side=3)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-text-to-a-plot-mtext-function.png" title="R software : Add a text to a plot" alt="R software : Add a text to a plot" width="240" /></p>
</div>
<div id="add-mathematical-annotation-to-a-plot" class="section level1">
<h1>Add mathematical annotation to a plot</h1>
<pre class="r"><code>plot(1:10, 1:10, 
     main="text(...) examples\n~~~~~~~~~~~")
text(4, 9, expression(hat(beta) == (X^t * X)^{-1} * X^t * y))
text(7, 4, expression(bar(x) == sum(frac(x[i], n), i==1, n)))</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/add-text-to-a-plot-math-expression.png" title="R software : Add a text to a plot" alt="R software : Add a text to a plot" width="240" /></p>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<p><span class="warning"> This analysis has been performed using <strong>R statistical software</strong> (ver. 3.1.0). </span></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->


<!-- END HTML -->]]></description>
			<pubDate>Sat, 06 Dec 2014 17:16:11 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[R plot pch symbols : The different point shapes available in R]]></title>
			<link>https://www.sthda.com/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r</link>
			<guid>https://www.sthda.com/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r</guid>
			<description><![CDATA[<!-- START HTML -->

  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">


<div id="TOC">
<ul>
<li><a href="#plotting-symbols">Plotting symbols</a></li>
<li><a href="#examples">Examples</a></li>
<li><a href="#r-script-to-generate-a-plot-of-point-shapes-in-r">R script to generate a plot of point shapes in R</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>

<p><br/></p>
<p>Different <strong>plotting symbols</strong> are available in <strong>R</strong>. The <strong>graphical</strong> argument used to specify <strong>point shapes</strong> is <strong>pch</strong>.</p>
<div id="plotting-symbols" class="section level1">
<h1>Plotting symbols</h1>
<p>The different <strong>points symbols</strong> commonly used in <strong>R</strong> are shown in the figure below :</p>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-plot-pch-symbols-points-in-r.png" title="R plot pch symbols" alt="R plot pch symbols" width="288" /></p>
<p><span class="success">The function used to generate this figure is provided at the end of this document</span></p>
<br/>
<div class="block">
<ul>
<li>pch = 0,square</li>
<li>pch = 1,circle</li>
<li>pch = 2,triangle point up</li>
<li>pch = 3,plus</li>
<li>pch = 4,cross</li>
<li>pch = 5,diamond</li>
<li>pch = 6,triangle point down</li>
<li>pch = 7,square cross</li>
<li>pch = 8,star</li>
<li>pch = 9,diamond plus</li>
<li>pch = 10,circle plus</li>
<li>pch = 11,triangles up and down</li>
<li>pch = 12,square plus</li>
<li>pch = 13,circle cross</li>
<li>pch = 14,square and triangle down</li>
<li>pch = 15, filled square</li>
<li>pch = 16, filled circle</li>
<li>pch = 17, filled triangle point-up</li>
<li>pch = 18, filled diamond</li>
<li>pch = 19, solid circle</li>
<li>pch = 20,bullet (smaller circle)</li>
<li>pch = 21, filled circle blue</li>
<li>pch = 22, filled square blue</li>
<li>pch = 23, filled diamond blue</li>
<li>pch = 24, filled triangle point-up blue</li>
<li>pch = 25, filled triangle point down blue</li>
</ul>
</div>
<p><br/></p>
<p><span class="warning"> Point can be omitted from the plot using <strong>pch = NA</strong>. </span></p>
</div>
<div id="examples" class="section level1">
<h1>Examples</h1>
<pre class="r"><code>x<-c(2.2, 3, 3.8, 4.5, 7, 8.5, 6.7, 5.5)
y<-c(4, 5.5, 4.5, 9, 11, 15.2, 13.3, 10.5)
# Plot points
plot(x, y)

# Change plotting symbol
# Use solid circle
plot(x, y, pch = 19)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-plot-pch-symbols-example1.png" title="plot of chunk example" alt="plot of chunk example" width="108" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-plot-pch-symbols-example2.png" title="plot of chunk example" alt="plot of chunk example" width="108" /></p>
<p><span class="warning">By default <strong>pch=1</strong></span></p>
<p>The following arguments can be used to change the <strong>color</strong> and the <strong>size</strong> of the points :</p>
<ul>
<li><strong>col</strong> : color (code or name) to use for the points</li>
<li><strong>bg</strong> : the <strong>background</strong> (or fill) color for the open <strong>plot symbols</strong>. It can be used only when <strong>pch = 21:25</strong>.</li>
<li><strong>cex</strong> : the size of <strong>pch symbols</strong></li>
<li><strong>lwd</strong> : the <strong>line width</strong> for the <strong>plotting symbols</strong></li>
</ul>
<pre class="r"><code># Change color
plot(x, y, pch=19, col="darkgreen", cex=1.5)

# Color can be a vector
plot(x, y, pch=19, col=c("green", "red"))

# change border, background color and line width
plot(x, y, pch = 24, cex=2, col="blue", bg="red", lwd=2)</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-plot-pch-symbols-change-color-and-size1.png" title="Change pch color and size" alt="Change pch color and size" width="108" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-plot-pch-symbols-change-color-and-size2.png" title="Change pch color and size" alt="Change pch color and size" width="108" /><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-plot-pch-symbols-change-color-and-size3.png" title="Change pch color and size" alt="Change pch color and size" width="108" /></p>
<p><span class="success"> Note that, only <strong>pch from 21 to 25</strong> can be filled using the argument <strong>bg=</strong> </span></p>
<p><span class="warning"> Other characters can be used to specify pch including “+”, “*“,”-“,”.“,”#, “%”, “o” </span></p>
<pre class="r"><code>set.seed(1234)
plot(x=rnorm(100), y=rnorm(100), pch="+")</code></pre>
<p><img src="https://www.sthda.com/english/sthda/RDoc/figure/graphs/r-plot-pch-symbols-other-symbols.png" title="Other symbols" alt="Other symbols" width="108" /></p>
</div>
<div id="r-script-to-generate-a-plot-of-point-shapes-in-r" class="section level1">
<h1>R script to generate a plot of point shapes in R</h1>
<p>Use the following R function to display a graph of the <strong>plotting symbols</strong> :</p>
<pre class="r"><code>#++++++++++++++++++++++++++++++++++++++++++++
#generate a plot of point shapes which R knows about.
#++++++++++++++++++++++++++++++++++++++++++++
generateRPointShapes<-function(){
  oldPar<-par()
  par(font=2, mar=c(0.5,0,0,0))
  y=rev(c(rep(1,6),rep(2,5), rep(3,5), rep(4,5), rep(5,5)))
  x=c(rep(1:5,5),6)
  plot(x, y, pch = 0:25, cex=1.5, ylim=c(1,5.5), xlim=c(1,6.5), 
       axes=FALSE, xlab="", ylab="", bg="blue")
  text(x, y, labels=0:25, pos=3)
  par(mar=oldPar$mar,font=oldPar$font )
}
generateRPointShapes()</code></pre>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<pre class="warning"><code>This analysis has been performed using R (ver. 3.1.0).</code></pre>
<p><br/></p>
</div>

<script>jQuery(document).ready(function () {
    jQuery('h1').addClass('wiki_paragraph1');
    jQuery('h2').addClass('wiki_paragraph2');
    jQuery('h3').addClass('wiki_paragraph3');
    jQuery('h4').addClass('wiki_paragraph4');
    });//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->


<!-- END HTML -->]]></description>
			<pubDate>Thu, 13 Nov 2014 18:49:02 +0100</pubDate>
			
		</item>
		
	</channel>
</rss>
