Last active
September 13, 2017 22:55
-
-
Save abresler/2d75bcd91a1ea3c72139 to your computer and use it in GitHub Desktop.
German Wermacht Dygraph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rvest) | |
library(dypgraph) | |
library(pipeR) | |
library(magrittr) | |
library(dplyr) | |
options(viewer = NULL) | |
url <- "http://www.feldgrau.com/stats.html" | |
stats <- | |
html(url) %>% | |
html_nodes("td td") %>% | |
html_text() %>>% | |
{.[4:192]} | |
stats[!stats == c('|')] %>>% {gsub(pattern = ",",'',.)} %>% as.numeric() -> s | |
s[is.na(s)] <- 0 | |
killed <- s[c(TRUE,FALSE)] | |
missing <- s[c(FALSE,TRUE)] | |
missing[is.na(missing)] <- 0 | |
missing %>% round(digits = 0) -> missing | |
missing/1000 -> missing | |
killed/1000 -> killed | |
killed+missing -> total | |
ts(start = c(1939, 9),end = c(1944,11),frequency = 12,data = total) -> Total | |
ts(start = c(1939, 9),end = c(1944,11),frequency = 12,data = killed) -> k | |
ts(start = c(1939, 9),end = c(1944,11),frequency = 12,data = missing) -> m | |
cbind(Total,k,m) -> ww2_germany | |
ww2_germany %>% dygraph(main = "German Wehrmacht Self Reported World War II Deaths and Casualties") %>% | |
dySeries("Total", drawPoints = TRUE, label = "Total Killed or Missing, Thousands") %>% | |
dySeries("m", drawPoints = FALSE ,label = "Missing in Action, Thousands") %>% | |
dySeries("k", stepPlot = TRUE, fillGraph = TRUE, label = 'Killed in Action, Thousands') %>% | |
dyOptions(colors = RColorBrewer::brewer.pal(3, "Set2")) %>% | |
dyOptions(axisLabelFontSize = 12,animatedZooms = TRUE,drawGrid = F) %>% | |
dyAxis("y", label = "Soliders in Thousands",axisLabelFormatter = "function (v) { | |
return v.toFixed(0); | |
}", | |
axisLabelFontSize = 10, | |
labelHeight = 100) %>% | |
dyLegend(width = 750,show = "onmouseover") %>% | |
dyHighlight(highlightCircleSize = 5, | |
highlightSeriesBackgroundAlpha = 0.2) %>% | |
#dyLegend(labelsSeparateLines = F,show = 'onmouseover',showZeroValues = F,hideOnMouseOut = T) %>% | |
dyRangeSelector(height = 50) %>% | |
dyRoller(rollPeriod = 1) %>% | |
dyEvent(date = "1939-09-27", "Warsaw Falls", labelLoc = "top",color = "black") %>% | |
dyEvent(date = "1940-06-22", "France Capitulates", labelLoc = "top", color = "blue") %>% | |
dyEvent(date = "1941-06-22", "Hitler Launches Barbarossa", labelLoc = "top", color = "red") %>% | |
dyEvent(date = "1941-08-20", "Siege of Leningrad Begins", labelLoc = "top", color = "red") %>% | |
dyEvent(date = "1941-12-11", "Germany Declares War on U.S.A", labelLoc = "top", color = "blue") %>% | |
dyEvent(date = "1942-09-13", "Germany Attacks Stalingrad", labelLoc = "top", color = "red") %>% | |
dyEvent(date = "1943-02-02", "6th Army Surrenders at Stalingrad", labelLoc = "top", color = "red") %>% | |
dyEvent(date = "1943-07-05", "Battle of Kursk", labelLoc = "top",color = "red") %>% | |
dyEvent(date = "1943-10-01", "Allies Take Naples", labelLoc = "top", color = "blue") %>% | |
dyEvent(date = "1944-01-27", "Red Army Frees Leningrad", labelLoc = "top",color = "red") %>% | |
dyEvent(date = "1944-06-06", "D-Day", labelLoc = "top",color = "blue") %>% | |
dyEvent(date = "1944-08-25", "Paris Liberated", labelLoc = "top",color = "blue") %>% | |
dyEvent(date = "1944-10-20", "Red Army Takes Yugoslavia", labelLoc = "top",color = "red") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment