<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/battle-maps-using-r-and-leaflet/"></div></div><div><a data-url="http://www.r-bloggers.com/battle-maps-using-r-and-leaflet/" data-counturl="http://www.r-bloggers.com/battle-maps-using-r-and-leaflet/" data-count="horizontal" data-text="Battle Maps Using R and Leaflet" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-datameister.blogspot.com/2016/05/battlemaps-using-r-and-leaflet.html"> Fear and Loathing in Data Science</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><span><i><b>“Here are those damned black hat fellows again.”</b></i></span><br><span>Attributed to men of the 26th North Carolina, Pettigrew’s Brigade at the Battle of Gettysburg in describing the “Iron Brigade”.</span><br><span><br></span>
<div><a target="_blank" href="https://2.bp.blogspot.com/-ouWUDcfa6Uk/Vy1gnjAcNcI/AAAAAAAAAV0/DNmNJzbU6zYAME7c7O0cT_I5do9IKLKXACKgB/s1600/iron.png"><img height="270" width="400" src="https://2.bp.blogspot.com/-ouWUDcfa6Uk/Vy1gnjAcNcI/AAAAAAAAAV0/DNmNJzbU6zYAME7c7O0cT_I5do9IKLKXACKgB/s400/iron.png" border="0"></a></div>
<p><span><br></span><span><br></span><span>A while back I created a post about plotting Russian airstrikes in Syria using the ggmap package. Of note was the commentary and method of taking that data and building an interactive map using the leaflet package by Bhaskar Karambelkar.  It inspired me to start work on a long-term goal I’ve had of creating a series of maps around the Battle of the Little Bighorn.  That project is on hold until I can do further research as the mystery of what happened to Custer and the 5 Companies of troopers under his direct command is quite contentious with pro and amateur historians.  Thus, I’ve decided to begin building a series of battle maps that I find interesting.  This first effort is around the initial engagement of Wadsworth’s Division from the Union 1st Corps against Heth’s Confederate Division on the 1st day of fighting.  The map depicts the attack by two of Heth’s Brigades under Archer and Davis against Cutler’s and Meredith’s Iron Brigade.  Both Archer’s and Davis’s Brigades were virtually wiped out with Davis’s men slaughtered in the infamous Railroad Cut.</span><br><span><br></span><span>The primary source I used was from the Civil War Trust website:</span><br><span><br></span><span><span>http://www.civilwar.org/battlefields/gettysburg/maps/gettysburg-battle-for.html</span></span><br><span><span><br></span></span><span><span>I served in the modern day namesake of The Iron Brigade, (2nd Brigade, 1st Armored Division). I hope to expand on the Gettysburg map and also include other maps such Kampfgruppe Peiper during the Battle of the Bulge, looking at the WikiLeaks data for Iraq and yes, tackle the Gordian Knot that is Custer’s Last Stand.</span></span><br><span><span><br></span></span><span><span>The link to the map is on RPubs:  </span><span>http://rpubs.com/Custer/iron_brigade  </span></span><br><span><span><br></span></span><span><span>The markers on the map signify individual regiments or artillery batteries.  You can click the markers to identify the unit.</span></span></p>
<p><span><span>And finally, here is the code.  Note that I used PowerPoint to create the .png files.</span></span><br><span><span><br></span></span><span><span>df = read.csv(“getty_ironbde.csv”)</span></span><br><span><span>str(df)</span></span><br><span><span>> str(df)</span></span><br><span><span>‘data.frame':<span> </span>65 obs. of  7 variables:</span></span><br><span><span> $ Regiment: Factor w/ 24 levels “13th AL”,”147th NY”,..: 16 7 5 19 9 3 21 11 15 22 …</span></span><br><span><span> $ Brigade : Factor w/ 10 levels “Archer”,”Cutler”,..: 7 7 7 7 7 2 2 4 4 9 …</span></span><br><span><span> $ Icon    : Factor w/ 13 levels “cCdr”,”cInf1″,..: 11 11 11 11 11 11 11 8 8 5 …</span></span><br><span><span> $ lat     : num  39.8 39.8 39.8 39.8 39.8 …</span></span><br><span><span> $ long    : num  -77.2 -77.2 -77.2 -77.3 -77.3 …</span></span><br><span><span> $ Time    : Factor w/ 3 levels “10:15 to 10:45 a.m.”,..: 3 3 3 3 3 3 3 3 3 3 …</span></span><br><span> $ Unit    : Factor w/ 25 levels “13th AL/Archer’s Brigade”,..: 16 7 5 19 9 3 21 11 15 22 …</span><br><span><span><br></span></span><span><span>library(leaflet)</span></span><br><span><span><br></span></span><span><span># Incorporate NATO symbology for icons</span></span><br><span><span>milIcons &lt;- iconList(</span></span><br><span><span>  uInf1 = makeIcon(“uInf1.png”, 48, 36),</span></span><br><span><span>  cInf1 = makeIcon(“cInf1.png”, 48, 36),</span></span><br><span><span>  uCav1 = makeIcon(“uCav1.png”, 48, 36),</span></span><br><span><span>  uArt1 = makeIcon(“uArt1.png”, 48, 36),</span></span><br><span><span>  uInf2 = makeIcon(“uInf2.png”, 48, 36),</span></span><br><span><span>  cInf2 = makeIcon(“cInf2.png”, 48, 36),</span></span><br><span><span>  uCav2 = makeIcon(“uCav2.png”, 48, 36),</span></span><br><span><span>  uArt2 = makeIcon(“uArt2.png”, 48, 36),</span></span><br><span><span>  uInf3 = makeIcon(“uInf3.png”, 48, 36),</span></span><br><span><span>  cInf3 = makeIcon(“cInf3.png”, 48, 36),</span></span><br><span><span>  uCav3 = makeIcon(“uCav3.png”, 48, 36),</span></span><br><span><span>  uArt3 = makeIcon(“uArt3.png”, 48, 36),</span></span><br><span><span>  cCdr = makeIcon(“cCdr.png”, 54, 40),</span></span><br><span><span>  uCdr = makeIcon(“uCdr.png”, 54, 40)</span></span><br><span><span>)</span></span><br><span><span><br></span></span><span><span># Spatial dataframe seems to work best</span></span><br><span><span>df2 &lt;- sp::SpatialPointsDataFrame(</span></span><br><span><span>  cbind(df$long, df$lat), data = data.frame(df$Unit, df$Icon, df$Time))</span></span><br><span><span><br></span></span><span><span>leaflet(df2) %>% </span></span><br><span><span>  addProviderTiles(“OpenStreetMap.BlackAndWhite”, group=”Black&amp;White”) %>%</span></span><br><span><span>  addProviderTiles(“Esri.NatGeoWorldMap”, group = “NatGeo”) %>%</span></span><br><span><span>  addProviderTiles(“MapQuestOpen.Aerial”, group = “Aerial”)%>%</span></span><br><span><span>  </span></span><br><span><span>  addLayersControl(</span></span><br><span><span>    baseGroups = c(“Black&amp;White”, “NatGeo”, “Aerial”),</span></span><br><span><span>    overlayGroups = df$Time,</span></span><br><span><span>    options = layersControlOptions(collapsed = FALSE))  %>%</span></span><br><span><span>      </span></span><br><span><span>  addMarkers(data=df2[1:22,], icon = ~ milIcons[df.Icon], </span></span><br><span><span>             group=”9:30 to 10:15 a.m.”,</span></span><br><span><span>             popup = ~ df.Unit) %>%</span></span><br><span><span>  addMarkers(data=df2[23:43,], icon = ~ milIcons[df.Icon], </span></span><br><span><span>             group=”10:15 to 10:45 a.m.”,</span></span><br><span><span>             popup = ~ df.Unit) %>%</span></span><br><span><span>  addMarkers(data=df2[44:65,], icon = ~ milIcons[df.Icon], </span></span><br><span><span>             group=”10:45 to 11:15 a.m.”, </span></span><br><span>             popup = ~ df.Unit) </span></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/battle-maps-using-r-and-leaflet/"></div></div><div><a data-url="http://www.r-bloggers.com/battle-maps-using-r-and-leaflet/" data-counturl="http://www.r-bloggers.com/battle-maps-using-r-and-leaflet/" data-count="vertical" data-text="Battle Maps Using R and Leaflet" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://r-datameister.blogspot.com/2016/05/battlemaps-using-r-and-leaflet.html"> Fear and Loathing in Data Science</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/CP8pMNMMN_0"></a></div>