<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/bitcoin-world-map-bubbles/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rud.is/b/2018/01/18/bitcoin-world-map-bubbles/"> R – rud.is</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>We’re doing some interesting studies (cybersecurity-wise, not finance-wise) on digital currency networks at work-work and — while I’m loathe to create a geo-map from IPv4 geolocation data — we:</p>
<ul>
<li>do get (often, woefully inaccurate) latitude &amp; longitude data from our geolocation service (I won’t name-and-shame here); and, </li>
<li>there <em>are</em> definite geo-aspects to the prevalence of mining nodes — especially Bitcoin; <em>and</em>, </li>
<li>I <em>have</em> been itching to play with the nascent <a rel="nofollow" href="https://github.com/arcticicestudio/nord" target="_blank">nord palette<img alt="🔗" src="https://i1.wp.com/s.w.org/images/core/emoji/2.3/72x72/1f517.png?w=456&ssl=1" class="wp-smiley" data-recalc-dims="1"></a> in a cartographical context…</li>
</ul>
<p>so I went on a small diversion to create a bubble plot of geographical Bitcoin node-prevalence.</p>
<p>I tweeted out said image and someone asked if there was code, hence this post.</p>
<p>You’ll be able to read about the methodology we used to capture the Bitcoin node data that underpins the map below later this year. For now, all I can say is that wasn’t garnered from joining the network-proper. </p>
<p>I’m including the geo-data in the <a rel="nofollow" href="https://gist.github.com/hrbrmstr/0303ba204e3f56def4daa261db340135" target="_blank">gist<img alt="🔗" src="https://i1.wp.com/s.w.org/images/core/emoji/2.3/72x72/1f517.png?w=456&ssl=1" class="wp-smiley" data-recalc-dims="1"></a>, but not the other data elements (you can easily find Bitcoin node data out on the internets from various free APIs and our data is on par with them).</p>
<p>I’m using <a rel="nofollow" href="https://github.com/hrbrmstr/swatches" target="_blank"><code>swatches</code><img alt="🔗" src="https://i1.wp.com/s.w.org/images/core/emoji/2.3/72x72/1f517.png?w=456&ssl=1" class="wp-smiley" data-recalc-dims="1"></a> for the nord palette since I was hand-picking colors, but you should use <a rel="nofollow" href="http://twitter.com/jakekaupp" target="_blank">@jakekaupp</a>’s most excellent <a rel="nofollow" href="https://github.com/jkaupp/nord" target="_blank"><code>nord</code> package<img alt="🔗" src="https://i1.wp.com/s.w.org/images/core/emoji/2.3/72x72/1f517.png?w=456&ssl=1" class="wp-smiley" data-recalc-dims="1"></a> if you want to use the various palettes more regularly.</p>
<p>I’ve blathered a bit about nord, so let’s start with that (and include the various other packages we’ll use later on):</p>
<pre><code>library(swatches)
library(ggalt) # devtools::install_github(&quot;hrbrmstr/ggalt&quot;)
library(hrbrthemes) # devtools::install_github(&quot;hrbrmstr/hrbrthemes&quot;)
library(tidyverse)

nord &lt;- read_palette(&quot;nord.ase&quot;)

show_palette(nord)</code></pre>
<p><a rel="nofollow" href="https://i1.wp.com/rud.is/b/wp-content/uploads/2018/01/nord-palette.png?ssl=1" target="_blank"><img data-orig-file="https://i1.wp.com/rud.is/b/wp-content/uploads/2018/01/nord-palette.png?fit=1774%2C640&amp;ssl=1" data-orig-size="1774,640" data-medium-file="https://i1.wp.com/rud.is/b/wp-content/uploads/2018/01/nord-palette.png?fit=300%2C108&amp;ssl=1" data-attachment-id="7969" data-image-meta="{" data-image-description="" src="https://i1.wp.com/rud.is/b/wp-content/uploads/2018/01/nord-palette.png?resize=780%2C281&ssl=1" data-permalink="https://rud.is/b/2018/01/18/bitcoin-world-map-bubbles/nord-palette/" data-large-file="https://i1.wp.com/rud.is/b/wp-content/uploads/2018/01/nord-palette.png?fit=530%2C191&amp;ssl=1" alt="" data-image-title="nord-palette" width="450" data-comments-opened="1" class="wp-image-7969" data-recalc-dims="1"></a></p>
<p>It may not be a perfect palette (accounting for all forms of vision issues and other technical details) but it was designed very well (IMO).</p>
<p>The rest is pretty straightforward:</p>
<ul>
<li>read in the bitcoin geo-data</li>
<li>count up by lat/lng</li>
<li>figure out which colors to use (that took a bit of trial-and-error)</li>
<li>tweak the rest of the ggplot2 canvas styling (that took a wee bit longer)</li>
</ul>
<p>I’m using development versions of two packages due to their added functionality not being on CRAN (yet). If you’d rather not use a dev-version of <code>hrbrthemes</code> just use a different <code>ipsum</code> theme vs the new <code>theme_ipsum_tw()</code>.</p>
<pre><code>read_csv(&quot;bitc.csv&quot;) %>%
  count(lng, lat, sort = TRUE) -> bubbles_df

world &lt;- map_data(&quot;world&quot;)
world &lt;- world[world$region != &quot;Antarctica&quot;, ]

ggplot() +
  geom_cartogram(
    data = world, map = world,
    aes(x = long, y = lat, map_id = region),
    color = nord[&quot;nord3&quot;], fill = nord[&quot;nord0&quot;], size = 0.125
  ) +
  geom_point(
    data = bubbles_df, aes(lng, lat, size = n), fill = nord[&quot;nord13&quot;],
    shape = 21, alpha = 2/3, stroke = 0.25, color = &quot;#2b2b2b&quot;
  ) +
  coord_proj(&quot;+proj=wintri&quot;) +
  scale_size_area(name = &quot;Node count&quot;, max_size = 20, labels = scales::comma) +
  labs(
    x = NULL, y = NULL,
    title = &quot;Bitcoin Network Geographic Distribution (all node types)&quot;,
    subtitle = &quot;(Using bubbles seemed appropriate for some, odd reason)&quot;,
    caption = &quot;Source: Rapid7 Project Sonar&quot;
  ) +
  theme_ipsum_tw(plot_title_size = 24, subtitle_size = 12) +
  theme(plot.title = element_text(color = nord[&quot;nord14&quot;], hjust = 0.5)) +
  theme(plot.subtitle = element_text(color = nord[&quot;nord14&quot;], hjust = 0.5)) +
  theme(panel.grid = element_blank()) +
  theme(plot.background = element_rect(fill = nord[&quot;nord3&quot;], color = nord[&quot;nord3&quot;])) +
  theme(panel.background = element_rect(fill = nord[&quot;nord3&quot;], color = nord[&quot;nord3&quot;])) +
  theme(legend.position = c(0.5, 0.05)) +
  theme(axis.text = element_blank()) +
  theme(legend.title = element_text(color = &quot;white&quot;)) +
  theme(legend.text = element_text(color = &quot;white&quot;)) +
  theme(legend.key = element_rect(fill = nord[&quot;nord3&quot;], color = nord[&quot;nord3&quot;])) +
  theme(legend.background = element_rect(fill = nord[&quot;nord3&quot;], color = nord[&quot;nord3&quot;])) +
  theme(legend.direction = &quot;horizontal&quot;)</code></pre>
<p><a rel="nofollow" href="https://i2.wp.com/rud.is/b/wp-content/uploads/2018/01/map-1.png?ssl=1" target="_blank"><img data-orig-file="https://i2.wp.com/rud.is/b/wp-content/uploads/2018/01/map-1.png?fit=1920%2C1536&amp;ssl=1" data-orig-size="1920,1536" data-medium-file="https://i2.wp.com/rud.is/b/wp-content/uploads/2018/01/map-1.png?fit=300%2C240&amp;ssl=1" data-attachment-id="7986" data-image-meta="{" data-image-description="" src="https://i2.wp.com/rud.is/b/wp-content/uploads/2018/01/map-1.png?resize=780%2C624&ssl=1" data-permalink="https://rud.is/b/2018/01/18/bitcoin-world-map-bubbles/map-1/" data-large-file="https://i2.wp.com/rud.is/b/wp-content/uploads/2018/01/map-1.png?fit=530%2C424&amp;ssl=1" alt="" data-image-title="map-1" width="450" data-comments-opened="1" class="wp-image-7986" data-recalc-dims="1"></a></p>
<p>As noted, the RStudio project associated with this post in in <a rel="nofollow" href="https://gist.github.com/hrbrmstr/0303ba204e3f56def4daa261db340135" target="_blank">this gist<img alt="🔗" src="https://i1.wp.com/s.w.org/images/core/emoji/2.3/72x72/1f517.png?w=456&ssl=1" class="wp-smiley" data-recalc-dims="1"></a>. Also, upon further data-inspection by <a rel="nofollow" href="http://twitter.com/jhartftw" target="_blank">@jhartftw</a>, we’ve discovered yet-more inconsistencies in the geo-mapping service data (there are <em>way</em> too many nodes in Paris, for example), but the main point of the post was to mostly show and play with the nord palette.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://rud.is/b/2018/01/18/bitcoin-world-map-bubbles/"> R – rud.is</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/u_0okEZrnhA" height="1"></a></div>