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

<channel>
	<title>histogram Archives - Data Analytics</title>
	<atom:link href="https://dataanalytics.org.uk/tag/histogram/feed/" rel="self" type="application/rss+xml" />
	<link>https://dataanalytics.org.uk/tag/histogram/</link>
	<description>Understanding Data</description>
	<lastBuildDate>Thu, 28 Jul 2022 15:39:09 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.1</generator>

<image>
	<url>https://dataanalytics.org.uk/wp-content/uploads/2019/11/cropped-DA-graph-logo-2019-cyan-600-32x32.png</url>
	<title>histogram Archives - Data Analytics</title>
	<link>https://dataanalytics.org.uk/tag/histogram/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Conditional density plots in R</title>
		<link>https://dataanalytics.org.uk/conditional-density-plots-in-r/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=conditional-density-plots-in-r</link>
		
		<dc:creator><![CDATA[gmark]]></dc:creator>
		<pubDate>Thu, 28 Jul 2022 15:39:09 +0000</pubDate>
				<category><![CDATA[Introduction-to-R]]></category>
		<category><![CDATA[cdplot]]></category>
		<category><![CDATA[data visualisation]]></category>
		<category><![CDATA[density]]></category>
		<category><![CDATA[density plot]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[histogram]]></category>
		<category><![CDATA[plot]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[visualisation]]></category>
		<category><![CDATA[visualization]]></category>
		<guid isPermaLink="false">https://www.dataanalytics.org.uk/?p=39529</guid>

					<description><![CDATA[<p>Conditional density plots Conditional density plots in R &#8212; how to draw a conditional density plot using R. A conditional density plot shows [&#8230;]</p>
<p>The post <a href="https://dataanalytics.org.uk/conditional-density-plots-in-r/">Conditional density plots in R</a> appeared first on <a href="https://dataanalytics.org.uk">Data Analytics</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1>Conditional density plots</h1>
<p>Conditional density plots in R &#8212; how to draw a conditional density plot using R. A conditional density plot shows the density of a sample split into groups.</p>
<p>Use <code>cdplot()</code> to draw a conditional density plot using R.</p>
<pre><code class="language-r" lang="r"><span style="color: #0000ff;">cdplot</span>(x, y,
       plot = TRUE, tol.ylab = 0.05, ylevels = NULL,
       bw = "nrd0", n = 512, from = NULL, to = NULL,
       col = NULL, border = 1, main = "", xlab = NULL, ylab = NULL,
       yaxlabels = NULL, xlim = NULL, ylim = c(0, 1), ...)
</code></pre>
<p>There are many potential parameters for <code>cdplot()</code> but the most helpful are:</p>
<figure>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Explanation</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>x</code>, <code>y</code></td>
<td>the data, specify <code>x</code> and <code>y</code> or use a <code>formula</code>. In any event <code>y</code> should be a <code>factor</code> and <code>x</code> a <code>numeric</code></td>
</tr>
<tr>
<td><code>ylevels</code></td>
<td>the order of the variables to be plotted</td>
</tr>
<tr>
<td><code>yaxlabels</code></td>
<td>labels for axis annotation</td>
</tr>
<tr>
<td><code>bw</code>, <code>n</code>, <code>from</code>, <code>to</code>, <code>...</code></td>
<td>arguments to pass to <code>density</code></td>
</tr>
</tbody>
</table>
</figure>
<p>There are several arguments related to the <code>density()</code> function, which in most cases you&#8217;ll never need to alter.</p>
<p>A basic plot requires a <code>factor</code> variable and a <code>numeric</code>:</p>
<pre><code class="language-r" lang="r"><span style="color: #0000ff;">cdplot</span>(tension ~ breaks, data = warpbreaks)
</code></pre>
<div id="attachment_39528" style="width: 510px" class="wp-caption aligncenter"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-39528" class="wp-image-39528" src="https://www.dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-warp-300x300.png" alt="" width="500" height="500" srcset="https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-warp-300x300.png 300w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-warp-150x150.png 150w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-warp-768x768.png 768w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-warp-600x600.png 600w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-warp-100x100.png 100w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-warp.png 900w" sizes="(max-width: 500px) 100vw, 500px" /><p id="caption-attachment-39528" class="wp-caption-text">A conditional density plot</p></div>
<p>You can use the <code>ylevels</code> argument to alter the order of the plotting of a <code>cdplot()</code>:</p>
<pre><code class="language-r" lang="r"><span style="color: #0000ff;">cdplot</span>(tension ~ breaks, data = warpbreaks, ylevels = 3:1)
</code></pre>
<div id="attachment_39527" style="width: 510px" class="wp-caption aligncenter"><img decoding="async" aria-describedby="caption-attachment-39527" class="wp-image-39527" src="https://www.dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-warp-rev-300x300.png" alt="" width="500" height="500" srcset="https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-warp-rev-300x300.png 300w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-warp-rev-150x150.png 150w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-warp-rev-768x768.png 768w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-warp-rev-600x600.png 600w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-warp-rev-100x100.png 100w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-warp-rev.png 900w" sizes="(max-width: 500px) 100vw, 500px" /><p id="caption-attachment-39527" class="wp-caption-text">Use the ylevels argument to change the order of a conditional density plot</p></div>
<p>Give customized names to the <code>factor</code> levels via the <code>yaxlabels</code> argument:</p>
<pre><code class="language-r" lang="r"><span style="color: #0000ff;">cdplot</span>(group ~ weight, data = PlantGrowth,
       yaxlabels = c("Control", "Treatment-1", "Treatment-2"))
</code></pre>
<div id="attachment_39525" style="width: 510px" class="wp-caption aligncenter"><img decoding="async" aria-describedby="caption-attachment-39525" class="wp-image-39525" src="https://www.dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-pg-300x300.png" alt="" width="500" height="500" srcset="https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-pg-300x300.png 300w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-pg-150x150.png 150w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-pg-768x768.png 768w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-pg-600x600.png 600w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-pg-100x100.png 100w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-pg.png 900w" sizes="(max-width: 500px) 100vw, 500px" /><p id="caption-attachment-39525" class="wp-caption-text">Custom factor labels via yaxlabels argument in cdplot</p></div>
<h2>Altering graphical appearance</h2>
<p>Only some of the general graphical parameters can be changed in <code>cdplot()</code>, as in the following example.</p>
<p>Use graphical parameters <code>col</code> and <code>border</code> to alter the appearance:</p>
<pre><span style="color: #0000ff;">cdplot</span>(spray ~ count, data = InsectSprays,
       col = <span style="color: #0000ff;">cm.colors</span>(6), border = "blue")</pre>
<div id="attachment_39526" style="width: 510px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-39526" class="wp-image-39526" src="https://www.dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-spray-300x300.png" alt="" width="500" height="500" srcset="https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-spray-300x300.png 300w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-spray-150x150.png 150w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-spray-768x768.png 768w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-spray-600x600.png 600w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-spray-100x100.png 100w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-spray.png 900w" sizes="(max-width: 500px) 100vw, 500px" /><p id="caption-attachment-39526" class="wp-caption-text">Basic graphical parameters col and border used to alter a cdplot</p></div>
<p>If you want to change any other graphical parameters you&#8217;ll need to call <code>par()</code> first:</p>
<pre><code class="language-r" lang="r">opar &lt;- <span style="color: #0000ff;">par</span>(las = 1, cex = 0.8, mar = c(5,7,2,3))

<span style="color: #0000ff;">cdplot</span>(feed ~ weight, data = chickwts, ylab = "")
<span style="color: #0000ff;">title</span>(ylab = "feed", line = 5)

<span style="color: #0000ff;">par</span>(opar)
</code></pre>
<div id="attachment_39524" style="width: 510px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-39524" class="wp-image-39524" src="https://www.dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-chick-300x300.png" alt="" width="500" height="500" srcset="https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-chick-300x300.png 300w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-chick-150x150.png 150w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-chick-768x768.png 768w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-chick-600x600.png 600w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-chick-100x100.png 100w, https://dataanalytics.org.uk/wp-content/uploads/2022/06/cdplot-chick.png 900w" sizes="(max-width: 500px) 100vw, 500px" /><p id="caption-attachment-39524" class="wp-caption-text">Use par() to set graphical parameters (other than col, border) in a cdplot</p></div>
<p>In the preceding example the margins were altered to allow the annotations to &#8220;fit&#8221;. In the <code>title</code> the annotation was shifted outwards.</p>
<p>This article is partly in support of my book <em>An Introduction to R</em> see the <a href="https://www.dataanalytics.org.uk/publications">publications page</a> for more information.</p>
<ul>
<li>For more articles look at the <a href="https://www.dataanalytics.org.uk/category/tips-and-tricks/">Tips and Tricks page</a> and look for the various categories or use the search box.</li>
<li>See also the <a href="#https://www.dataanalytics.org.uk/data-analytics-knowledge-base-tips-tricks-r-excel/">Knowledge Base</a> where there are other topics related to R and data science.</li>
<li>An Introduction to R will be published by <a href="https://pelagicpublishing.com/">Pelagic Publishing</a>. <a href="https://pelagicpublishing.com/pages/search-results-page?q=Mark%20Gardener">See all my books at Pelagic Publishing</a>.</li>
<li>Visit our other site at <a href="https://www.gardenersown.co.uk/">GardenersOwn</a> for a more ecological matters.</li>
</ul>
<p>The post <a href="https://dataanalytics.org.uk/conditional-density-plots-in-r/">Conditional density plots in R</a> appeared first on <a href="https://dataanalytics.org.uk">Data Analytics</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Add more to a histogram in R</title>
		<link>https://dataanalytics.org.uk/add-more-to-a-histogram-in-r/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=add-more-to-a-histogram-in-r</link>
		
		<dc:creator><![CDATA[gmark]]></dc:creator>
		<pubDate>Tue, 19 Nov 2019 10:23:23 +0000</pubDate>
				<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[histogram]]></category>
		<guid isPermaLink="false">https://www.dataanalytics.org.uk/?p=5189</guid>

					<description><![CDATA[<p>Add more to a histogram in R A histogram is a standard way to present the distribution of a sample of numbers. A [&#8230;]</p>
<p>The post <a href="https://dataanalytics.org.uk/add-more-to-a-histogram-in-r/">Add more to a histogram in R</a> appeared first on <a href="https://dataanalytics.org.uk">Data Analytics</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1 id="section-intro">Add more to a histogram in R</h1>
<p>A histogram is a standard way to present the distribution of a sample of numbers. A basic histogram is useful but it is easy to add more to a histogram in R to produce an even more informative plot. In this article you’ll see how to add a rug and a strip-chart to a basic historgram using simple R commands.</p>
<h2 id="section-basic">A basic histogram</h2>
<p>It is easy to make a histogram using R with the <code>hist()</code> command. For example:</p>
<pre><code><span style="color: #0000ff;">set.seed</span>(123)
x &lt;- <span style="color: #0000ff;">norm</span>(n = 50, mean = 10, sd = 1)
<span style="color: #0000ff;">hist</span>(x, col = "skyblue")
</code></pre>
<p>Produces a histogram resembling this:</p>
<figure><img loading="lazy" decoding="async" class="alignnone wp-image-5191 size-full" src="https://www.dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-basic.png" alt="" width="1000" height="1000" srcset="https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-basic.png 1000w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-basic-300x300.png 300w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-basic-150x150.png 150w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-basic-768x768.png 768w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-basic-600x600.png 600w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-basic-100x100.png 100w" sizes="(max-width: 1000px) 100vw, 1000px" /></p>
<h2 id="section-rug">Add a rug</h2>
<p>A rug plot can be added to more or less any graphic. The <code>rug()</code> command can add the rug to any side of the plot:</p>
<ul>
<li><code>side = 1</code> is the bottom axis</li>
<li><code>side = 2</code> is the left axis</li>
</ul>
<p>You can alter the colour and width of the rug lines using regular graphical parameters:</p>
<pre><code><span style="color: #0000ff;">rug</span>(x, side = 1, col = "blue")
</code></pre>
<p>Adds the rug like so:</p>
<figure><img loading="lazy" decoding="async" class="alignnone size-full wp-image-5193" src="https://www.dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-rug.png" alt="" width="1000" height="1000" srcset="https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-rug.png 1000w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-rug-300x300.png 300w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-rug-150x150.png 150w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-rug-768x768.png 768w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-rug-600x600.png 600w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-rug-100x100.png 100w" sizes="(max-width: 1000px) 100vw, 1000px" /></figure>
<h2 id="section-strip">Add a strip chart</h2>
<p>A strip chart can also be added to any chart via the <code>stripchart()</code> command. However, you also need to specify <code>add = TRUE</code> to the command. Giving a bit of <code>jitter</code> helps to separate out points that are coincident:</p>
<pre><code><span style="color: #0000ff;">stripchart</span>(x,
           method = "jitter",
           pch = 23,
           bg = "pink",
           add = TRUE)
</code></pre>
<p>The final plot looks like so:</p>
<p><!-- Use this as the featured image --></p>
<figure><img loading="lazy" decoding="async" class="alignnone size-full wp-image-5192" src="https://www.dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-rug-strip1.png" alt="" width="1000" height="1000" srcset="https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-rug-strip1.png 1000w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-rug-strip1-300x300.png 300w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-rug-strip1-150x150.png 150w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-rug-strip1-768x768.png 768w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-rug-strip1-600x600.png 600w, https://dataanalytics.org.uk/wp-content/uploads/2019/11/rplot-hist-rug-strip1-100x100.png 100w" sizes="(max-width: 1000px) 100vw, 1000px" /></figure>
<p>There are many additional options for the <code>stripchart()</code> command; use <code>help(stripchart)</code> in R to find out more. Look out for other articles in our <a href="https://www.dataanalytics.org.uk/category/tips-and-tricks/">Tips &amp; Tricks</a> pages.</figure>
<p>The post <a href="https://dataanalytics.org.uk/add-more-to-a-histogram-in-r/">Add more to a histogram in R</a> appeared first on <a href="https://dataanalytics.org.uk">Data Analytics</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
