<?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>paranormal &#8211; Weird Data Science</title>
	<atom:link href="https://www.weirddatascience.net/category/paranormal/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.weirddatascience.net</link>
	<description>Paranormal Distributions. Cyclopean Data. Esoteric Regression.</description>
	<lastBuildDate>Wed, 27 Nov 2019 22:52:54 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<site xmlns="com-wordpress:feed-additions:1">143387998</site>	<item>
		<title>Mapping Paranormal Manifestations in the British Isles</title>
		<link>https://www.weirddatascience.net/2018/04/10/mapping-paranormal-manifestations-in-the-british-isles/</link>
					<comments>https://www.weirddatascience.net/2018/04/10/mapping-paranormal-manifestations-in-the-british-isles/#comments</comments>
		
		<dc:creator><![CDATA[moth]]></dc:creator>
		<pubDate>Tue, 10 Apr 2018 20:08:23 +0000</pubDate>
				<category><![CDATA[cryptozoology]]></category>
		<category><![CDATA[ghosts]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[paranormal]]></category>
		<category><![CDATA[spatial analysis]]></category>
		<category><![CDATA[ufo]]></category>
		<guid isPermaLink="false">http://www.weirddatascience.net/blog/?p=284</guid>

					<description><![CDATA[<div class="mh-excerpt">In our last entry we analysed the relative frequency of paranormal manifestations in the British Isles according to the Paranormal Database. The results of that analysis showed that hauntings of various forms are by far the most commonly-reported paranormal encounter in the British Isles, followed by cryptozoological sightings. <a class="mh-excerpt-more" href="https://www.weirddatascience.net/2018/04/10/mapping-paranormal-manifestations-in-the-british-isles/" title="Mapping Paranormal Manifestations in the British Isles">[...]</a></div>]]></description>
										<content:encoded><![CDATA[<p>In our <a href="http://www.weirddatascience.net/index.php/2018/03/17/paranormal-manifestations-in-the-british-isles/" rel="noopener noreferrer" target="_blank">last entry</a> we analysed the relative frequency of paranormal manifestations in the British Isles according to the <a href="http://www.paranormaldatabase.com" rel="noopener noreferrer" target="_blank">Paranormal Database</a>. The results of that analysis showed that hauntings of various forms are by far the most commonly-reported paranormal encounter in the British Isles, followed by cryptozoological sightings.</p>
<p>This is, however, relatively unsatisfactory. It is much more interesting to know where such sightings and events occur. Are there particular haunts of restless spirits? Do mysterious beasts roam in particular regions more than others? To answer these questions, we need to delve into the specific locations of different reports.</p>
<p>The Paranormal Database does contain location information, but it is given very informally. To map this we can make use of <a href="https://developers.google.com/maps/documentation/geolocation/intro">Google&#8217;s Geolocation API</a> to convert free text strings, such as &#8220;<a href="https://www.nationaltrust.org.uk/features/a-haunted-library-and-a-bookish-ghost" rel="noopener noreferrer" target="_blank">Felbrigg Hall, Norfolk</a>&#8221; into usable latitude and longitude coordinates. (In this case: <a href="https://goo.gl/maps/xr3vZHB4Kwq">52.907479, 1.259443</a>.)</p>
<p>The geolocation is not perfect, but with sufficient manipulation of the service it was possible to produce geolocated coordinates for most of the entries in the database. In order to represent these meaningfully, we have also subdivided the entries into a different types. The original Paranormal Database data is subdivided into twenty categories, which we have reduced to six for easier presentation. This includes collapsing the various kinds of haunting, from poltergeists to &#8216;post-mortem manifestions&#8217;, simply to hauntings. Similarly, we combine alien big cats and <a href="https://en.wikipedia.org/wiki/Black_Shuck" rel="noopener noreferrer" target="_blank">shuck</a> into the broader family of cryptozoology.</p>
<p>With this in place, we can see the overall distribution of paranormal events in the British Isles.</p>
<figure id="attachment_289" aria-describedby="caption-attachment-289" style="width: 1024px" class="wp-caption aligncenter"><a href="http://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal.png"><img fetchpriority="high" decoding="async" data-attachment-id="289" data-permalink="https://www.weirddatascience.net/2018/04/10/mapping-paranormal-manifestations-in-the-british-isles/paranormal-2/" data-orig-file="https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal.png" data-orig-size="1920,1080" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="paranormal" data-image-description="" data-image-caption="&lt;p&gt;Paranormal manifestations in the British Isles.&lt;/p&gt;
" data-large-file="https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-1024x576.png" src="http://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-1024x576.png" class="wp-image-289 size-large" width="1024" height="576" alt="" srcset="https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-1024x576.png 1024w, https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-640x360.png 640w, https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-300x169.png 300w, https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-768x432.png 768w, https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-64x36.png 64w, https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal.png 1920w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption id="caption-attachment-289" class="wp-caption-text">Paranormal manifestations in the British Isles. (<a href="http://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal.pdf" rel="noopener noreferrer" target="_blank">PDF Version</a>.)</figcaption></figure>
<p>As might be expected, London is a dark and sinister nexus of paranormal activity. Hauntings, as might be expected from their overall frequency, dominate the majority of the British Isles. Moving north, particularly as we reach the Scottish Highlands, cryptozoological sightings begin to challenge hauntings as the most common supernatural event. We can also see significant cryptozoology in the Hebrides, Orkney, and Shetland &#8212; the archipelagos that surround the Scottish mainland.</p>
<p>Both Wales, Ireland, and Cornwall are significantly less densely haunted in the Paranormal Database, with the majority of sightings falling in England.</p>
<p>This overall view, however, combines a number of very different phenomena. Where, for example, are we most likely to receive a visitation from a restless spectre as opposed to being pursued by a savage and unnatural beast?</p>
<p>By breaking down the sightings into different types, and plotting a heatmap of event density over each, we can identify the regions in which different manifestations cluster.</p>
<figure id="attachment_292" aria-describedby="caption-attachment-292" style="width: 1024px" class="wp-caption aligncenter"><a href="http://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-density.png"><img decoding="async" data-attachment-id="292" data-permalink="https://www.weirddatascience.net/2018/04/10/mapping-paranormal-manifestations-in-the-british-isles/paranormal-density/" data-orig-file="https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-density.png" data-orig-size="1920,1080" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="paranormal-density" data-image-description="" data-image-caption="&lt;p&gt;Density plot of paranormal manifestations in the British Isles&lt;/p&gt;
" data-large-file="https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-density-1024x576.png" src="http://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-density-1024x576.png" class="size-large wp-image-292" width="1024" height="576" alt="" srcset="https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-density-1024x576.png 1024w, https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-density-640x360.png 640w, https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-density-300x169.png 300w, https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-density-768x432.png 768w, https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-density-64x36.png 64w, https://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-density.png 1920w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption id="caption-attachment-292" class="wp-caption-text">Density plot of paranormal manifestations in the British Isles. (<a href="http://www.weirddatascience.net/wp-content/uploads/2018/04/paranormal-density.pdf" rel="noopener noreferrer" target="_blank">PDF Version</a>.)</figcaption></figure>
<p>This view highlights several points of interest.</p>
<p>Firstly, London&#8217;s preeminent position is not for all forms of paranormal activity. Hauntings are extremely dense in London, however the rest of England is also well-populated. As might be expected from the first diagram, the less population-dense regions further north have produced fewer sad echoes of mortality. Despite its general reputation Edinburgh, while noticeably haunted, cannot compare with many regions of England.</p>
<p>Cryptozoologically, however, London is far from dominant. Whilst unknown beings may lurk in the foetid sewers of the capital, they clearly prefer the wide open spaces &#8212; both the Norfolk and Suffolk Broads are rife with cryptids, as are the Hebrides, Orkney, and Shetland that were noticeable earlier. Finally, visitors to Cornwall will pass through areas of increasing <a href="https://en.wikipedia.org/wiki/Beast_of_Bodmin_Moor" rel="noopener noreferrer" target="_blank">monstrous activity</a>.</p>
<p>UFO&#8217;s also appear to be attracted to East Anglia most strongly, and are otherwise most common in the large population centres of England. Less obviously, there is a noticeable density of UFO activity on the Pembrokeshire Coast, in the south-west of Wales.</p>
<p>Monsters, which in this classification includes werewolves, vampires, and dragons, produce a surprising cluster in North Wales, around Snowdonia. The most significant monstrous sightings, however, appear to be in Exmoor; again on the south-western tip of the British Isles.</p>
<p>The final categories of manifestation include legends, fairies, and a catch-all category of &#8216;other manifestations&#8217; that include mysterious orbs, talking trees, bleeding stones, and the supernatural impressions left by the work of <a href="https://en.wikipedia.org/wiki/John_Dee" rel="noopener noreferrer" target="_blank">John Dee</a>. As might be expected, this last category is more uniformly distributed across the country, matching high-density population areas. There is, however, another notable cluster in Cornwall for this category.</p>
<p>In conclusion, then, the British Isles are teeming with paranormal activity. Entities from beyond the grave lie close at all times, with twisted monstrosities roaming the wild spaces. UFOs descend from the night sky to terrorise the coastal regions.</p>
<p>From this analysis, ghost hunters should concentrate on London for the best chance of a sighting, although almost any of the large centres of population provide a reasonable chance of spectral apparitions. Cryptid researchers should concentrate in East Anglia or head north to the islands beyond Scotland. Those seeking contact with extraterrestrials should focus particularly on the east coast of Suffolk, or travel to the south-west of Wales. Paranormal investigators whose interests lie in legends or monsters, or less specific strange entities, would be well-advised to visit Cornwall.</p>
<p>Code for the plotting elements of this analyis are given below, following on from the scraping and parsing code in our <a href="http://www.weirddatascience.net/index.php/2018/03/17/paranormal-manifestations-in-the-british-isles/" rel="noopener noreferrer" target="_blank">previous post</a>. The geolocation step required a more significant effort, and will be the focus of a future code-based post.</p>
<p>You can keep up to date with our latest paranormal data mining on Twitter at <a href="https://twitter.com/weirddatasci" rel="noopener noreferrer" target="_blank">@WeirdDataSci</a>.</p>
<div class="su-accordion su-u-trim">
<div class="su-spoiler su-spoiler-style-fancy su-spoiler-icon-chevron su-spoiler-closed" data-scroll-offset="0" data-anchor-in-url="no"><div class="su-spoiler-title" tabindex="0" role="button"><span class="su-spoiler-icon"></span>Show analysis code</div><div class="su-spoiler-content su-u-clearfix su-u-trim">
<p><strong>Data:</strong></p>
<ul>
<li>The Paranormal Database: <a href="http://www.paranormaldatabase.com">http://www.paranormaldatabase.com</a></li>
</ul>
<p><strong>Other:</strong></p>
<ul>
<li>JSL Ancient font: <a href="http://www.1001fonts.com/jsl-ancient-font.html">http://www.1001fonts.com/jsl-ancient-font.html</a></li>
<li>Cowplot: <a href="https://cran.r-project.org/web/packages/cowplot/vignettes/introduction.html">https://cran.r-project.org/web/packages/cowplot/vignettes/introduction.html</a></li>
</ul>
<p><strong>Combined Plot Code:</strong></p>
[code language=&#8221;r&#8221;]
library(spatstat)</p>
<p>library(rgdal)<br />
library(maptools)</p>
<p>library(tidyverse)<br />
library(magrittr)<br />
library(ggplot2)<br />
library(ggthemes)<br />
library(raster)<br />
library(viridis)<br />
library(scales)</p>
<p>library(sf) </p>
<p>library(showtext)</p>
<p>library(grid)</p>
<p>library(cowplot)<br />
library(magick)</p>
<p># Function to combine certain paranormal report types into broader categories<br />
combine_paranormal_types &lt;- function( type ) {</p>
<p>	# levels( paranormal_tbl$type )<br />
	# [1] &quot;Alien Big Cat&quot;                &quot;Crisis Manifestation&quot;<br />
	# [3] &quot;Cryptozoology&quot;                &quot;Curse&quot;<br />
	# [5] &quot;Dragon&quot;                       &quot;Environmental Manifestation&quot;<br />
	# [7] &quot;Experimental Manifestation&quot;   &quot;Fairy&quot;<br />
	# [9] &quot;Haunting Manifestation&quot;       &quot;Legend&quot;<br />
	# [11] &quot;Manifestation of the Living&quot;  &quot;Other&quot;<br />
	# [13] &quot;Poltergeist&quot;                  &quot;Post-Mortem Manifestation&quot;<br />
	# [15] &quot;Shuck&quot;                        &quot;Spontaneous Human Combustion&quot;<br />
	# [17] &quot;UFO&quot;                          &quot;Unknown Ghost Type&quot;<br />
	# [19] &quot;Vampire&quot;                      &quot;Werewolf&quot;                   </p>
<p>	# Simple lookup<br />
	case_when(<br />
				 type %in% c(&quot;Alien Big Cat&quot;, &quot;Cryptozoology&quot;, &quot;Shuck&quot;) ~ &quot;Cryptozoology&quot;,<br />
				 type %in% c(&quot;Dragon&quot;, &quot;Vampire&quot;, &quot;Werewolf&quot; ) ~ &quot;Monster&quot;,<br />
				 type %in% c(&quot;Crisis Manifestation&quot;, &quot;Environmental Manifestation&quot;, &quot;Experimental Manifestation&quot;, &quot;Haunting Manifestation&quot;, &quot;Manifestation of the Living&quot;, &quot;Poltergeist&quot;, &quot;Post-Mortem Manifestation&quot;, &quot;Unknown Ghost Type&quot;) ~ &quot;Haunting&quot;,<br />
				 type %in% c(&quot;Legend&quot;, &quot;Fairy&quot;, &quot;Curse&quot;) ~ &quot;Legend&quot;,<br />
				 type %in% c(&quot;Spontaneous Human Combustion&quot;, &quot;Other&quot;) ~ &quot;Other&quot;,<br />
				 type %in% c(&quot;UFO&quot;) ~ &quot;UFO&quot;<br />
				 )</p>
<p>}</p>
<p># Load font<br />
font_add( &quot;mapfont&quot;, &quot;/usr/share/fonts/TTF/weird/JANCIENT.TTF&quot; )<br />
showtext_auto()</p>
<p># Read world shapefile data and tranform to an appropriate projection.<br />
# Limit to the UK, Ireland, and the Isle of Man<br />
world &lt;- readOGR( dsn=&#8217;data/ne/10m_cultural&#8217;, layer=&#8217;ne_10m_admin_0_countries&#8217; )<br />
world_subset &lt;- world[ world$iso_a2 %in% c(&quot;GB&quot;,&quot;IE&quot;,&quot;IM&quot;), ]
world_subset &lt;- spTransform(world_subset,CRS(&quot;+init=epsg:4326&quot;))<br />
world_df &lt;- fortify( world_subset )</p>
<p># Read paranormal database<br />
paranormal_tbl &lt;- as.tibble( read.csv( file=&quot;data/paranormal_database.csv&quot; ) )</p>
<p># Convert the paranormal dataframe to a spatial dataframe that contains<br />
# explicit longitude and latitude projected appropriately for plotting.<br />
coordinates( paranormal_tbl ) &lt;- ~lng+lat<br />
proj4string( paranormal_tbl )&lt;-CRS(&quot;+init=epsg:4326&quot;)<br />
paranormal_tbl &lt;- spTransform(paranormal_tbl,CRS(proj4string(paranormal_tbl)))</p>
<p># Restrict paranormal_tbl to those points in the polygons defined by world_subset<br />
paranormal_tbl_rows &lt;- paranormal_tbl %&gt;%<br />
	over( world_subset ) %&gt;%<br />
	is.na() %&gt;%<br />
	not() %&gt;%<br />
	rowSums() %&gt;%<br />
	`!=`(0) %&gt;%<br />
	which</p>
<p>paranormal_tbl &lt;- as.tibble( paranormal_tbl[ paranormal_tbl_rows, ] )</p>
<p>paranormal_tbl$combined_type &lt;- paranormal_tbl$type %&gt;%<br />
	map( combine_paranormal_types ) %&gt;%<br />
	unlist</p>
<p># Show the map<br />
gp &lt;- ggplot() + </p>
<p>	geom_map( data = world_df, aes( map_id=id ), colour = &quot;#3c3f4a&quot;, fill = &quot;transparent&quot;, size = 0.5, map = world_df )</p>
<p># Display each sighting as geom_point. Use a level of transparency to highlight<br />
# more common areas. (On the 20180401 dataset, this reports that 16035 out of<br />
# the original 19387 points lie in the appropriate area. Several are geolocated<br />
# outside of the UK &#8212; the geolocation should be run again with better bounds<br />
# checking and region preference.)<br />
gp &lt;- gp + geom_point(data=paranormal_tbl, aes(x=lng, y=lat, colour=combined_type ), size=0.5, shape=17, alpha=0.9) +<br />
	expand_limits(x = world_df$long, y = world_df$lat)  </p>
<p>gp &lt;- gp +	</p>
<p>	# Theming<br />
	theme_map() +<br />
	theme(<br />
			plot.background = element_rect(fill = &quot;transparent&quot;, colour = &quot;transparent&quot;),<br />
			panel.border = element_blank(),<br />
			plot.title = element_text( size=24, colour=&quot;#3c3f4a&quot;, family=&quot;mapfont&quot; ),<br />
			text = element_text( size=14, color=&quot;#3c3f4a&quot;, family=&quot;mapfont&quot; ),<br />
			) +</p>
<p>	theme(<br />
			legend.background = element_rect( colour =&quot;transparent&quot;, fill = &quot;transparent&quot; ),<br />
			legend.key = element_rect(fill = &quot;transparent&quot;, colour=&quot;transparent&quot;),<br />
			legend.position = &quot;left&quot;,<br />
			legend.justification = c(0,0)<br />
			) +</p>
<p>	guides( fill = guide_colourbar( title.position=&quot;top&quot;, direction=&quot;vertical&quot;, barwidth=32, nrow=1 ) ) +<br />
	guides(colour = guide_legend(override.aes = list(size=2)) ) +<br />
	scale_colour_manual(<br />
		values = c(&quot;#00EA38&quot;,&quot;#417CCC&quot;,&quot;#B79F00&quot;,&quot;#F564E3&quot;,&quot;#00BFC4&quot;,&quot;#F8766D&quot;),<br />
		breaks = c(&quot;Haunting&quot;, &quot;Cryptozoology&quot;, &quot;Monster&quot;, &quot;Legend&quot;, &quot;UFO&quot;, &quot;Other&quot; ),<br />
		name = &quot;Manifestation&quot; ) +<br />
	coord_fixed( ratio=1.2 )</p>
<p># Cowplot trick for ggtitle<br />
title &lt;- ggdraw() +<br />
	draw_label(&quot;Paranormal Manifestations in the British Isles&quot;, fontfamily=&quot;mapfont&quot;, colour = &quot;#3c3f4a&quot;, size=24, hjust=0, vjust=1, x=0.02, y=0.88) +<br />
	draw_label(&quot;http://www.weirddatascience.net | @WeirdDataSci&quot;, fontfamily=&quot;mapfont&quot;, colour = &quot;#3c3f4a&quot;, size=14, hjust=0, vjust=1, x=0.02, y=0.40)</p>
<p>data_label &lt;- ggdraw() +<br />
	draw_label(&quot;Data from: http://www.paranormaldatabase.com&quot;, fontfamily=&quot;mapfont&quot;, colour = &quot;#3c3f4a&quot;, size=12, hjust=1, x=0.98 ) </p>
<p>paranormal_legend &lt;- get_legend(gp)</p>
<p># Remove legend from internal plot<br />
gp &lt;- gp + theme(legend.position=&#8217;none&#8217;)</p>
<p>tgp &lt;- plot_grid(title, gp, data_label, ncol=1, rel_heights=c(0.1, 1, 0.1)) </p>
<p>vellum_plot &lt;- ggdraw() +<br />
	draw_image(&quot;img/vellum.jpg&quot;, scale=1.4 ) +<br />
	draw_plot(tgp) +<br />
	draw_plot( paranormal_legend, 0.02, 0.03 )</p>
<p>save_plot(&quot;output/paranormal.pdf&quot;,<br />
			vellum_plot,<br />
			base_width = 16,<br />
			base_height = 9,<br />
			base_aspect_ratio = 1.78 )<br />
[/code]
<p><strong>Per-Manifestation Density Plot Code:</strong></p>
[code language=&#8221;r&#8221;]
library(spatstat)</p>
<p>library(rgdal)<br />
library(maptools)</p>
<p>library(tidyverse)<br />
library(magrittr)<br />
library(ggplot2)<br />
library(ggthemes)<br />
library(raster)<br />
library(viridis)<br />
library(scales)</p>
<p>library(sf) </p>
<p>library(showtext)</p>
<p>library(grid)</p>
<p>library(cowplot)<br />
library(magick)</p>
<p># Function to combine certain paranormal report types into broader categories<br />
combine_paranormal_types &lt;- function( type ) {</p>
<p>	# levels( paranormal_tbl$type )<br />
	# [1] &quot;Alien Big Cat&quot;                &quot;Crisis Manifestation&quot;<br />
	# [3] &quot;Cryptozoology&quot;                &quot;Curse&quot;<br />
	# [5] &quot;Dragon&quot;                       &quot;Environmental Manifestation&quot;<br />
	# [7] &quot;Experimental Manifestation&quot;   &quot;Fairy&quot;<br />
	# [9] &quot;Haunting Manifestation&quot;       &quot;Legend&quot;<br />
	# [11] &quot;Manifestation of the Living&quot;  &quot;Other&quot;<br />
	# [13] &quot;Poltergeist&quot;                  &quot;Post-Mortem Manifestation&quot;<br />
	# [15] &quot;Shuck&quot;                        &quot;Spontaneous Human Combustion&quot;<br />
	# [17] &quot;UFO&quot;                          &quot;Unknown Ghost Type&quot;<br />
	# [19] &quot;Vampire&quot;                      &quot;Werewolf&quot;                   </p>
<p>	# Simple lookup<br />
	case_when(<br />
				 type %in% c(&quot;Alien Big Cat&quot;, &quot;Cryptozoology&quot;, &quot;Shuck&quot;) ~ &quot;Cryptozoology&quot;,<br />
				 type %in% c(&quot;Dragon&quot;, &quot;Vampire&quot;, &quot;Werewolf&quot; ) ~ &quot;Monster&quot;,<br />
				 type %in% c(&quot;Crisis Manifestation&quot;, &quot;Environmental Manifestation&quot;, &quot;Experimental Manifestation&quot;, &quot;Haunting Manifestation&quot;, &quot;Manifestation of the Living&quot;, &quot;Poltergeist&quot;, &quot;Post-Mortem Manifestation&quot;, &quot;Unknown Ghost Type&quot;) ~ &quot;Haunting&quot;,<br />
				 type %in% c(&quot;Legend&quot;, &quot;Fairy&quot;, &quot;Curse&quot;) ~ &quot;Legend&quot;,<br />
				 type %in% c(&quot;Spontaneous Human Combustion&quot;, &quot;Other&quot;) ~ &quot;Other Manifestation&quot;,<br />
				 type %in% c(&quot;UFO&quot;) ~ &quot;UFO&quot;<br />
				 )</p>
<p>}</p>
<p># Load font<br />
font_add( &quot;mapfont&quot;, &quot;/usr/share/fonts/TTF/weird/JANCIENT.TTF&quot; )<br />
showtext_auto()</p>
<p># Read world shapefile data and tranform to an appropriate projection.<br />
# Limit to the UK, Ireland, and the Isle of Man<br />
world &lt;- readOGR( dsn=&#8217;data/ne/10m_cultural&#8217;, layer=&#8217;ne_10m_admin_0_countries&#8217; )<br />
world_subset &lt;- world[ world$iso_a2 %in% c(&quot;GB&quot;,&quot;IE&quot;, &quot;IM&quot;), ]
world_subset &lt;- spTransform(world_subset,CRS(&quot;+init=epsg:4326&quot;))<br />
world_df &lt;- fortify( world_subset )</p>
<p># Read UK Major Cities datafile<br />
#cities &lt;- readOGR( dsn=&#8217;data/ons_uk_cities&#8217;, layer=&#8217;Major_Towns_and_Cities_December_2015_Boundaries&#8217; )<br />
#cities &lt;- spTransform(cities,CRS(&quot;+init=epsg:4326&quot;))<br />
#cities_fortified &lt;- fortify( cities )<br />
#cities_centroids_tbl &lt;- as.tibble( coordinates( cities ) )<br />
#cities_tbl &lt;- as.tibble( cbind( cities@data$tcity15nm, cities_centroids_tbl ))<br />
#colnames(cities_tbl) &lt;- c( &quot;city&quot;, &quot;lng&quot;, &quot;lat&quot; )</p>
<p># As the polygons are more confusing than useful, instead label centroids</p>
<p># Read paranormal database<br />
paranormal_tbl &lt;- as.tibble( read.csv( file=&quot;data/paranormal_database.csv&quot; ) )</p>
<p>paranormal_tbl$combined_type &lt;- paranormal_tbl$type %&gt;%<br />
	map( combine_paranormal_types ) %&gt;%<br />
	unlist</p>
<p># Convert the paranormal dataframe to a spatial dataframe that contains<br />
# explicit longitude and latitude projected appropriately for plotting.<br />
coordinates( paranormal_tbl ) &lt;- ~lng+lat<br />
proj4string( paranormal_tbl )&lt;-CRS(&quot;+init=epsg:4326&quot;)<br />
paranormal_tbl_spatial &lt;- spTransform(paranormal_tbl,CRS(proj4string(paranormal_tbl)))</p>
<p># Restrict paranormal_tbl to those points in the polygons defined by world_subset<br />
paranormal_tbl_rows &lt;- paranormal_tbl_spatial %&gt;%<br />
	over( world_subset ) %&gt;%<br />
	is.na() %&gt;%<br />
	not() %&gt;%<br />
	rowSums() %&gt;%<br />
	`!=`(0) %&gt;%<br />
	which</p>
<p>#paranormal_tbl &lt;- as.tibble( paranormal_tbl_spatial[ paranormal_tbl_rows, ] )</p>
<p># Create window for spatial analysis<br />
paranormal_owin &lt;- as.owin.SpatialPolygons(world_subset)</p>
<p># Function to plot density of a specific manifestation type.<br />
# plot_resolution is for the density raster, and is mainly used for quick prototyping of the output.<br />
density_plot &lt;- function( paranormal_type, plot_resolution = 1024 ) {</p>
<p>	cat( paste0( &quot;Plotting density: &quot;, paranormal_type, &quot;&#8230; &quot; ) )</p>
<p>	paranormal_tbl_spatial &lt;- paranormal_tbl_spatial[ which( paranormal_tbl_spatial$combined_type == paranormal_type ), ]
<p>	paranormal_ppp &lt;-<br />
		ppp( 	x=coordinates(paranormal_tbl_spatial)[,1],<br />
			 y=coordinates(paranormal_tbl_spatial)[,2],<br />
			 window = paranormal_owin )</p>
<p>	# This discards &#8216;illegal&#8217; points outside of the window<br />
	paranormal_ppp &lt;- as.ppp(paranormal_ppp)</p>
<p>	paranormal_density &lt;- density( paranormal_ppp, diggle=T, sigma=0.4, dimyx=c(plot_resolution,plot_resolution) )</p>
<p>	# Make density image object usable by ggplot as a raster<br />
	paranormal_density_raster &lt;- raster( paranormal_density )<br />
	raster_tbl &lt;- as.tibble( rasterToPoints( paranormal_density_raster ) )</p>
<p>	# Show the map<br />
	gp &lt;- ggplot() + </p>
<p>		geom_map( data = world_df, aes( map_id=id ), colour = &quot;#3c3f4a&quot;, fill = &quot;transparent&quot;, size = 0.8, map = world_df ) +</p>
<p>		# Add density of sightings as raster.<br />
		geom_raster( data = raster_tbl, alpha=0.8, aes( x=x, y=y, fill=layer), show.legend=TRUE ) +<br />
		scale_fill_viridis( option=&quot;magma&quot;, direction = -1, name=&quot;Density&quot; ) </p>
<p>	gp &lt;- gp +	</p>
<p>		# Theming<br />
		theme_map() + </p>
<p>		theme(<br />
				plot.background = element_rect(fill = &quot;transparent&quot;, colour = &quot;transparent&quot;),<br />
				panel.border = element_blank(),<br />
				plot.title = element_text( size=12, colour=&quot;#3c3f4a&quot;, family=&quot;mapfont&quot; ),<br />
				text = element_text( size=12, color=&quot;#3c3f4a&quot;, family=&quot;mapfont&quot; ),<br />
				) +</p>
<p>		theme(<br />
				legend.background = element_rect( colour =&quot;transparent&quot;, fill = &quot;transparent&quot; ),<br />
				legend.key = element_rect(fill = &quot;transparent&quot;, colour=&quot;transparent&quot;),<br />
				legend.position = c(0,0),<br />
				legend.justification = c(0,0)<br />
		) +</p>
<p>		guides( fill = guide_colourbar( title.position=&quot;top&quot;, direction=&quot;horizontal&quot;, barwidth=6, barheight=0.4 ) ) +</p>
<p>                # Fix the ratio of the plot to avoid distorting the UK<br />
		coord_fixed( ratio=1.2 )</p>
<p>	cat(&quot;done.\n&quot; )<br />
	return(gp)<br />
}</p>
<p># Calculate densities for each phenomenon<br />
phenomena &lt;- unique( paranormal_tbl$combined_type )</p>
<p>gp_list &lt;- phenomena %&gt;%<br />
	map( density_plot, 1024 )</p>
<p># Plot as a grid with cowplot<br />
theme_set(theme_cowplot(font_size=4, font_family = &quot;mapfont&quot; ) )<br />
gp &lt;- plot_grid( plotlist=gp_list,<br />
			labels = phenomena,<br />
			label_colour = &quot;#3c3f4a&quot; )</p>
<p># Cowplot trick for ggtitle<br />
title &lt;- ggdraw() +<br />
	draw_label(&quot;Density of Paranormal Manifestations in the British Isles&quot;, fontfamily=&quot;mapfont&quot;, colour = &quot;#3c3f4a&quot;, size=24, hjust=0, vjust=1, x=0.02, y=0.88) +<br />
	draw_label(&quot;http://www.weirddatascience.net | @WeirdDataSci&quot;, fontfamily=&quot;mapfont&quot;, colour = &quot;#3c3f4a&quot;, size=14, hjust=0, vjust=1, x=0.02, y=0.40)</p>
<p>data_label &lt;- ggdraw() +<br />
	draw_label(&quot;Data from: http://www.paranormaldatabase.com&quot;, fontfamily=&quot;mapfont&quot;, colour = &quot;#3c3f4a&quot;, size=12, hjust=1, x=0.98 )</p>
<p>tgp &lt;- plot_grid(title, gp, data_label, ncol=1, rel_heights=c(0.1, 1, 0.1)) </p>
<p>vellum_plot &lt;- ggdraw() +<br />
	draw_image(&quot;img/vellum.jpg&quot;, scale=1.4 ) +<br />
	draw_plot(tgp)</p>
<p>save_plot(&quot;output/paranormal-density.pdf&quot;,<br />
				vellum_plot,<br />
				base_width = 16,<br />
				base_height = 9,<br />
			        base_aspect_ratio = 1.78 )<br />
[/code]
</div></div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.weirddatascience.net/2018/04/10/mapping-paranormal-manifestations-in-the-british-isles/feed/</wfw:commentRss>
			<slash:comments>14</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">284</post-id>	</item>
		<item>
		<title>Paranormal Manifestations in the British Isles</title>
		<link>https://www.weirddatascience.net/2018/03/17/paranormal-manifestations-in-the-british-isles/</link>
					<comments>https://www.weirddatascience.net/2018/03/17/paranormal-manifestations-in-the-british-isles/#comments</comments>
		
		<dc:creator><![CDATA[moth]]></dc:creator>
		<pubDate>Sat, 17 Mar 2018 09:20:09 +0000</pubDate>
				<category><![CDATA[cryptozoology]]></category>
		<category><![CDATA[ghosts]]></category>
		<category><![CDATA[paranormal]]></category>
		<category><![CDATA[scraping]]></category>
		<guid isPermaLink="false">http://www.weirddatascience.net/blog/?p=212</guid>

					<description><![CDATA[<div class="mh-excerpt">The British Isles are ancient, haunted places. Pre-Roman legends and folk songs are filled with dragons, magic, and strange, wild creatures. Spirits, fairies, and all kinds of imps and goblins roam the countryside with intent ranging from the mischievous to the malevolent. Will-o&#8217;-the-wisps lead unwary travellers deep into <a class="mh-excerpt-more" href="https://www.weirddatascience.net/2018/03/17/paranormal-manifestations-in-the-british-isles/" title="Paranormal Manifestations in the British Isles">[...]</a></div>]]></description>
										<content:encoded><![CDATA[<p>The British Isles are ancient, haunted places. Pre-Roman legends and folk songs are filled with dragons, magic, and strange, wild creatures. Spirits, fairies, and all kinds of imps and goblins roam the countryside with intent ranging from the mischievous to the malevolent. Will-o&#8217;-the-wisps lead unwary travellers deep into marshes in the night, before vanishing. The sad ghosts of past tragedies reside in ancient castles and stately homes.</p>
<p>In more recent history, strange beasts have been rumoured to live wild in the open spaces, whether large predators escaped from zoos, the last survivals of prehistory, or spirits. Every village, town, and county has its own stories and traditions.</p>
<p>The <a href="http://www.paranormaldatabase.com">Paranormal Database</a> is a collection of both traditional and recent paranormal events in Britain and Ireland. It contains details of almost 20,000 hauntings, cryptozoological sightings, legends, monsters, UFO&#8217;s, and other strange phenomena, with details of the date and time of sightings, the location, and brief descriptions.</p>
<p>The data is not easily accessible beyond directly reading pages, and required some effort and time to scrape and make usable. Paranormal Database entries contain names, dates, locations, and comments as unstructured text and so will require further effort to perform a more thorough analysis. The R code used to scrape the website is included at the end of this post.</p>
<p>To understand the range and breadth of the paranormal life of the British Isles, we will focus on the data stored in the Paranormal Database. For this initial entry, we will take a first look at the data and get an overview of what mind-numbing horrors are most commonly encountered by the unsuspecting traveller in the United Kingdom and beyond.</p>
<figure id="attachment_216" aria-describedby="caption-attachment-216" style="width: 1024px" class="wp-caption aligncenter"><a href="http://www.weirddatascience.net/wp-content/uploads/2018/03/haunting.png"><img decoding="async" data-attachment-id="216" data-permalink="https://www.weirddatascience.net/2018/03/17/paranormal-manifestations-in-the-british-isles/haunting/" data-orig-file="https://www.weirddatascience.net/wp-content/uploads/2018/03/haunting.png" data-orig-size="1920,1080" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="paranormal_occurrences" data-image-description="" data-image-caption="&lt;p&gt;Frequency of paranormal sightings in the British Isles.&lt;/p&gt;
" data-large-file="https://www.weirddatascience.net/wp-content/uploads/2018/03/haunting-1024x576.png" src="http://www.weirddatascience.net/wp-content/uploads/2018/03/haunting-1024x576.png" class="size-large wp-image-216" width="1024" height="576" alt="" srcset="https://www.weirddatascience.net/wp-content/uploads/2018/03/haunting-1024x576.png 1024w, https://www.weirddatascience.net/wp-content/uploads/2018/03/haunting-640x360.png 640w, https://www.weirddatascience.net/wp-content/uploads/2018/03/haunting-300x169.png 300w, https://www.weirddatascience.net/wp-content/uploads/2018/03/haunting-768x432.png 768w, https://www.weirddatascience.net/wp-content/uploads/2018/03/haunting-64x36.png 64w, https://www.weirddatascience.net/wp-content/uploads/2018/03/haunting.png 1920w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption id="caption-attachment-216" class="wp-caption-text">Frequency of paranormal sightings in the British Isles. (<a href="http://www.weirddatascience.net/wp-content/uploads/2018/03/haunting.pdf">PDF version</a>)</figcaption></figure>
<div class="su-accordion su-u-trim">
<div class="su-spoiler su-spoiler-style-fancy su-spoiler-icon-chevron su-spoiler-closed" data-scroll-offset="0" data-anchor-in-url="no"><div class="su-spoiler-title" tabindex="0" role="button"><span class="su-spoiler-icon"></span>Show frequency table of manifestations</div><div class="su-spoiler-content su-u-clearfix su-u-trim">
<h2 id="tablepress-1-name" class="tablepress-table-name tablepress-table-name-id-1">Paranormal Manifestations in the British Isles</h2>

<table id="tablepress-1" class="tablepress tablepress-id-1" aria-labelledby="tablepress-1-name">
<thead>
<tr class="row-1">
	<th class="column-1">Manifestation Type</th><th class="column-2">Occurrences</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">Haunting Manifestation</td><td class="column-2">12376</td>
</tr>
<tr class="row-3">
	<td class="column-1">Legend</td><td class="column-2">1662</td>
</tr>
<tr class="row-4">
	<td class="column-1">Cryptozoology</td><td class="column-2">835</td>
</tr>
<tr class="row-5">
	<td class="column-1">Shuck</td><td class="column-2">688</td>
</tr>
<tr class="row-6">
	<td class="column-1">Poltergeist</td><td class="column-2">625</td>
</tr>
<tr class="row-7">
	<td class="column-1">Unknown Ghost Type</td><td class="column-2">614</td>
</tr>
<tr class="row-8">
	<td class="column-1">Fairy</td><td class="column-2">550</td>
</tr>
<tr class="row-9">
	<td class="column-1">Other</td><td class="column-2">427</td>
</tr>
<tr class="row-10">
	<td class="column-1">Alien Big Cat</td><td class="column-2">382</td>
</tr>
<tr class="row-11">
	<td class="column-1">UFO</td><td class="column-2">336</td>
</tr>
<tr class="row-12">
	<td class="column-1">Crisis Manifestation</td><td class="column-2">277</td>
</tr>
<tr class="row-13">
	<td class="column-1">Dragon</td><td class="column-2">190</td>
</tr>
<tr class="row-14">
	<td class="column-1">Curse</td><td class="column-2">183</td>
</tr>
<tr class="row-15">
	<td class="column-1">Post-Mortem Manifestation</td><td class="column-2">179</td>
</tr>
<tr class="row-16">
	<td class="column-1">Environmental Manifestation</td><td class="column-2">152</td>
</tr>
<tr class="row-17">
	<td class="column-1">Manifestation of the Living</td><td class="column-2">44</td>
</tr>
<tr class="row-18">
	<td class="column-1">Werewolf</td><td class="column-2">36</td>
</tr>
<tr class="row-19">
	<td class="column-1">Vampire</td><td class="column-2">34</td>
</tr>
<tr class="row-20">
	<td class="column-1">Spontaneous Human Combustion</td><td class="column-2">28</td>
</tr>
<tr class="row-21">
	<td class="column-1">Experimental Manifestation</td><td class="column-2">2</td>
</tr>
</tbody>
</table>
<!-- #tablepress-1 from cache -->
</div></div>
</div>
<p>As we can see from the diagram and the frequency table, hauntings are by far the most common manifestation in paranormal Britain, being an order of magnitude greater than the number of legend recorded. Examining the list, beyond &#8220;Haunting Manifestation&#8221; we see that several of the most common types are variants: both poltergeist activity and unknown types of ghost represent a significant amount of the total events recorded.</p>
<p>Cryptozoology, in its various forms, is also well-represented. The phenomenon of the <a href="https://en.wikipedia.org/wiki/Black_Shuck">Black Shuck</a>, a ghostly black dog, is one of the highest categories next to the main cryptozoology category, and alien big cats are close behind. Dragons, werewolves, and vampires, perhaps, deserve to be classed more as monstrous entities than cryptozoological oddities and are, in any case, far less common.</p>
<p>In brief conclusion, then, the unquiet dead are by far the most numerous beings to trouble the unhappy folk of the British Isles; twisted mockeries of natural fauna are far from rare.</p>
<p>Do particular phenomena cluster in regions and, if so, where? Are werewolves truly more commonly seen when the moon is full? Have certain manifestations become more common as time passes? Are certain sightings clustered temporally as well as geographically? Are the most haunted areas also the most cryptozoologically active? With access to the full horror of the data we can begin to answer these question about the darkest corners of the United Kingdom.</p>
<p>Full code for scraping the data and producing the plot are given below.</p>
<p>You can keep up to date with our latest visions of the statistical unknown on Twitter at <a href="https://twitter.com/weirddatasci" rel="noopener" target="_blank">@WeirdDataSci</a>.</p>
<div class="su-accordion su-u-trim">
<div class="su-spoiler su-spoiler-style-fancy su-spoiler-icon-chevron su-spoiler-closed" data-scroll-offset="0" data-anchor-in-url="no"><div class="su-spoiler-title" tabindex="0" role="button"><span class="su-spoiler-icon"></span>Show analysis code</div><div class="su-spoiler-content su-u-clearfix su-u-trim">
<p><strong>Data:</strong></p>
<ul>
<li>The Paranormal Database: <a href="http://www.paranormaldatabase.com">http://www.paranormaldatabase.com</a></li>
</ul>
<p><strong>Other:</strong></p>
<ul>
<li>JSL Ancient font: <a href="http://www.1001fonts.com/jsl-ancient-font.html">http://www.1001fonts.com/jsl-ancient-font.html</a></li>
<li>Rvest web scraping library: <a href="http://blog.rstudio.com/2014/11/24/rvest-easy-web-scraping-with-r/">http://blog.rstudio.com/2014/11/24/rvest-easy-web-scraping-with-r/</a> | <a href="https://cran.r-project.org/web/packages/rvest/index.html">https://cran.r-project.org/web/packages/rvest/index.html</a></li>
<li>xkcd styling for ggplot2: <a href="http://xkcd.r-forge.r-project.org/">http://xkcd.r-forge.r-project.org/</a></li>
</ul>
<p><strong>Paranormal Database Scraping Code:</strong></p>
[code language=&#8221;r&#8221;]
library(rvest)<br />
library(magrittr)<br />
library(tidyr)<br />
library(stringr)<br />
library(dplyr)</p>
<p># Base URL for scraping<br />
paranormal.base &lt;- &quot;http://www.paranormaldatabase.com&quot;</p>
<p># Extract links from a given page. Return a list with full URLs.<br />
extract.links &lt;- function( in.html, base.url ) {</p>
<p>	# Read the page and extract any links from the &#8216;hero-unit&#8217; div.<br />
	# Extract all links, making relatives absolute.<br />
	in.html %&gt;%<br />
		html_nodes( &#8216;.hero-unit&#8217; ) %&gt;%<br />
		html_nodes( &#8216;a&#8217; ) %&gt;%<br />
		html_attr( &#8216;href&#8217; ) %&gt;%<br />
		url_absolute( base.url )</p>
<p>}</p>
<p># Function to extract a paranormal database entries page into a dataframe.<br />
# Returns a dataframe of the entries from the given HTML.<br />
extract.entries &lt;- function( in.html ) {</p>
<p>	# Select all table cells with a width of 100% &#8212; ugly, but identifies the<br />
	# entries themselves.<br />
	page.entries &lt;- in.html %&gt;%<br />
		html_nodes( xpath=&#8217;//td[ contains( @width, &quot;100&quot; ) ]&#8217; ) %&gt;%<br />
		html_text() %&gt;%<br />
		str_replace_all( &quot;[\r\n]&quot; , &quot;&quot; )</p>
<p>	# If any entries were found, process them.<br />
	if( ( length( page.entries ) &gt; 0 ) &amp;&amp;<br />
		(str_detect(page.entries, &quot;(.*[[:graph:]])\\s*Location: (.*[[:graph:]])\\s*Type: (.*[[:graph:]])\\s*Date / Time: (.*[[:graph:]])\\s*Further Comments: (.*[[:graph:]])\\s*&quot;)) ) {<br />
		# Each entry is a string containing:<br />
		# &#8211; Location:<br />
		# &#8211; Type:<br />
		# &#8211; Date / Time:<br />
		# &#8211; Further Comments:<br />
		# So split the string on these and put the entries into a dataframe.<br />
		page.entries.df &lt;- data.frame( entry=page.entries) %&gt;%<br />
			tidyr::extract(entry, into=c(&#8216;title&#8217;, &#8216;location&#8217;, &#8216;type&#8217;, &#8216;date&#8217;, &#8216;comments&#8217;), &quot;(.*[[:graph:]])\\s*Location: (.*[[:graph:]])\\s*Type: (.*[[:graph:]])\\s*Date / Time: (.*[[:graph:]])\\s*Further Comments: (.*[[:graph:]])\\s*&quot; )</p>
<p>		# Further split these into subtypes where appropriate. Both &#8216;location&#8217; and &#8216;type&#8217; are often split into a main and a subtype by a space-surrounded hyphen.<br />
		# As we&#8217;ll do this twice, make it a function. This takes a base column name, a new name for the sub-column, and the separator string.<br />
		coalesce.join &lt;- function( base.data, base.column, sub.column, separator ) {</p>
<p>			base.data &lt;- base.data %&gt;%<br />
				tidyr::extract( base.column, into=c(&quot;tmp.main&quot;, sub.column), separator, remove=FALSE)</p>
<p>			# Combine the old base column with the new tmp.main column, using base.column to fill in the NAs in tmp.main<br />
			# where the separator was not matched.<br />
			base.data[ base.column ] &lt;- coalesce( base.data[[ &quot;tmp.main&quot; ]], base.data[[ base.column ]] )<br />
			base.data &lt;- base.data %&gt;%<br />
				select(-one_of(&quot;tmp.main&quot;))</p>
<p>		}</p>
<p>		# Split &#8216;type&#8217;<br />
		page.entries.df &lt;- coalesce.join( page.entries.df, &quot;type&quot;, &quot;subtype&quot;, &quot;(.*) &#8211; (.*)&quot; )<br />
		page.entries.df &lt;- coalesce.join( page.entries.df, &quot;location&quot;, &quot;sublocation&quot;, &quot;(.*) &#8211; (.*)&quot; )</p>
<p>		page.entries.df</p>
<p>	}</p>
<p>}</p>
<p># Read each page&#8217;s links to populate a list to process.<br />
# Each page contains a &quot;Return to Regional Listing&quot; link, and a link to enter the listings.<br />
# That listing can be either a straight entries page, or a link to subpages.</p>
<p># Starting with the base page, pull every link in the main &#8216;hero-unit&#8217; div and<br />
# add it to a &#8216;to.process&#8217; vector, checking that that URL is not already<br />
# listed. Also pass along a &#8216;processed&#8217; vector in the recursive calls so that<br />
# we don&#8217;t overly duplicate results.</p>
<p># WARNING: As written, this will cause a lot of duplication due to the lack of<br />
# global list of processed links. As this was a one-off script, I haven&#8217;t fixed this.</p>
<p># Base URL to being processing<br />
paranormal.regions &lt;- &quot;http://www.paranormaldatabase.com/regions/regions.htm&quot;</p>
<p># Recursively process the top-level URL<br />
scrape.recurse &lt;- function( in.url, processed ) {</p>
<p>	message( paste(&quot;Processing&quot;, in.url ) )</p>
<p>	# Try to fetch this URL and any subpages.<br />
	# Warn on failure<br />
	page &lt;- tryCatch(<br />
						  {<br />
							  # Fetch and parse HTML of current page.<br />
							  read_html( in.url )<br />
						  },<br />
						  error=function( cond ) {<br />
							  message( paste( &quot;URL caused an error:&quot;, in.url ))<br />
							  message( &quot;Error message:&quot;)<br />
							  message( cond )<br />
							  return( NULL )<br />
						  },<br />
						  warning=function( cond ) {<br />
							  message( paste( &quot;URL caused a warning:&quot;, in.url ))<br />
							  message( &quot;Warning message:&quot;)<br />
							  message( cond )<br />
							  return( NULL )<br />
						  },<br />
						  finally={<br />
						  }<br />
						  )</p>
<p>	if( is.null( page ) ) {<br />
		return( NULL )<br />
	}<br />
	else {<br />
		# Get the current page&#8217;s entries<br />
		links &lt;- extract.links( page, in.url )<br />
		entries &lt;- extract.entries( page )</p>
<p>		lapply( entries$title, function(x) cat( x, &quot;&#8230; &quot;, sep=&quot;&quot; ) )<br />
		cat( &quot;\n&quot;)</p>
<p>		# Recurse, but don&#8217;t follow any known links<br />
		new.entries &lt;-<br />
			lapply( setdiff( links, processed ), function(x) scrape.recurse( x, union( links, processed ) ) ) %&gt;%<br />
			bind_rows()</p>
<p>		# Bind entries from sub-pages to this page&#8217;s entries.<br />
		all.entries &lt;- bind_rows( entries, new.entries )</p>
<p>		# Report success and return results<br />
		message( paste( &quot;Successfully processed:&quot;, in.url ) )<br />
		return( all.entries )<br />
	}</p>
<p>}</p>
<p># Run the scraping and parsing, then remove duplicates.<br />
all.entries &lt;- scrape.recurse( paranormal.regions, paranormal.regions )<br />
paranormal.df &lt;- unique( all.entries )</p>
<p># Manually fix some type entries.<br />
paranormal.df$type[ which( paranormal.df$type == &quot;legend&quot; ) ] &lt;- &quot;Legend&quot;<br />
paranormal.df$type[ which( paranormal.df$type == &quot;Haunting Manifestation?&quot; ) ] &lt;- &quot;Haunting Manifestation&quot;<br />
paranormal.df$type[ which( paranormal.df$type == &quot;SHC&quot; ) ] &lt;- &quot;Spontaneous Human Combustion&quot;<br />
paranormal.df$type[ which( paranormal.df$type == &quot;ABC&quot; ) ] &lt;- &quot;Alien Big Cat&quot;</p>
<p># With all values scraped, save data.<br />
save( paranormal.df, file=&quot;paranormal.Rdata&quot;)</p>
[/code]
<p><strong>Paranormal Manifestations in the British Isles Plotting Code:</strong><br />
[code language=&#8221;r&#8221;]
library(ggplot2)<br />
library(jpeg)<br />
library(xkcd)<br />
library(showtext)<br />
library(grid)<br />
library(gridExtra)</p>
<p># Create a summary barplot for paranormal activity in the UK.</p>
<p># Load the data from scraping http://www.paranormaldatabase.com/<br />
load( &quot;../data/paranormal.Rdata&quot; )</p>
<p># Process the data to frequency counts of each type of event.<br />
counts &lt;- table( paranormal.df$type )<br />
df &lt;- as.data.frame.table( sort(counts, decreasing=FALSE) )<br />
colnames( df ) &lt;- c(&quot;type&quot;, &quot;frequency&quot; )</p>
<p># Create the plot.<br />
# Use the xkcd package to create irregular bars for a hand-drawn look.<br />
df$xmin &lt;- 1<br />
df$xmax &lt;- df$frequency<br />
df$ymin &lt;- as.numeric(df$type) &#8211; 0.1<br />
df$ymax &lt;- as.numeric(df$type) + 0.1</p>
<p>xrange &lt;- range( min( df$xmin ), max( df$xmax ) )<br />
yrange &lt;- range( min( df$ymin ), max( df$ymax ) + 1 )<br />
mapping &lt;- aes( xmin=xmin, ymin=ymin, xmax=xmax, ymax=ymax )</p>
<p># Load font<br />
font_add( &quot;handwriting&quot;, &quot;/usr/share/fonts/TTF/weird/JANCIENT.TTF&quot; )<br />
showtext_auto()</p>
<p># Load background image.<br />
bg.image &lt;- jpeg::readJPEG(&quot;img/vellum.jpg&quot;)<br />
bg.grob &lt;- rasterGrob( bg.image, interpolate=TRUE,<br />
							 width = 1.8,<br />
							 height = 1.4 )</p>
<p>gp &lt;- ggplot( data=paranormal.df, aes( x=frequency, y=type ) ) +<br />
			annotation_custom( bg.grob, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf ) +<br />
			xkcdrect( mapping, df, alpha=0.6, fill=&quot;#8a0707&quot;, size=1 ) +<br />
			xkcdaxis( xrange, yrange ) +<br />
			theme(<br />
				text = element_text( size=12, color=&quot;#232732&quot;, family=&quot;handwriting&quot; ),<br />
				plot.background = element_rect(fill = &quot;transparent&quot;, color=&quot;transparent&quot;),<br />
				panel.background = element_rect(fill = &quot;transparent&quot;, color=&quot;transparent&quot;),<br />
				plot.title = element_text( size=24, colour=&quot;#232732&quot;, family=&quot;handwriting&quot; ),<br />
				axis.title = element_text( size=18, colour=&quot;#232732&quot;, family=&quot;handwriting&quot; ),<br />
				axis.text.x=element_text( size=12, color=&quot;#232732&quot;, family=&quot;handwriting&quot; ),<br />
				axis.text.y=element_text( size=12, color=&quot;#232732&quot;, family=&quot;handwriting&quot;, hjust=1) ) +<br />
			scale_y_discrete( labels=c( as.character( df$type ) ) ) +<br />
			scale_x_continuous( expand = c( 0, 0 ) ) +<br />
			ylab( &quot;Phenomenon&quot; ) +<br />
			xlab( &quot;Occurrence&quot; ) +<br />
			labs( caption = &quot;Data from: http://www.paranormaldatabase.com&quot; ) +<br />
			ggtitle(&quot;Paranormal Manifestations in the British Isles&quot;, subtitle=&quot;http://www.weirddatascience.net | @WeirdDataSci&quot;)</p>
<p># To allow the background image to extend to the edge of the panel, we have to generate<br />
# a gtable directly from gp, then turn off clipping.<br />
p2 &lt;- ggplot_gtable(ggplot_build(gp))<br />
p2$layout$clip[p2$layout$name==&quot;panel&quot;] &lt;- &quot;off&quot;</p>
<p># To create the output, we need to call grid.draw on the gtable.<br />
# Use the pdf device to draw directly to preserve clipping and fonts.<br />
# showtext has to be called explicitly in here, for some reason.<br />
pdf( file=&quot;output/haunting.pdf&quot;, width=16, height=9 )<br />
showtext_begin()<br />
grid.draw(p2)<br />
showtext_end()<br />
dev.off()</p>
[/code]
</div></div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.weirddatascience.net/2018/03/17/paranormal-manifestations-in-the-british-isles/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">212</post-id>	</item>
	</channel>
</rss>
