```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

library(dplyr)
library(ggplot2)
library(scales)
library(ggmap)

cities <- read.csv("https://cs.brown.edu/courses/cs100/lectures/scripts/napoleon/minard.cities.csv", row.names = 1, stringsAsFactors = FALSE)
troops <- read.csv("https://cs.brown.edu/courses/cs100/lectures/scripts/napoleon/minard.troops.csv", row.names = 1, stringsAsFactors = FALSE)

```

```{r layer1}
layer1 <- ggplot(data = troops,
                 aes(x = long, y=lat)) +
  xlab("") + ylab("") + 
  ggtitle("Napoleon's March to Russia")
layer1
```


```{r layer2}
layer2 <- geom_path(
  data = troops,
  aes(linewidth = survivors,color = direction,
      group = division),
  lineend = "square",
  linejoin = "round")
layer1 + layer2
```

```{r layer3}
layer3 <- geom_text(
  data = cities,
  aes(label = city),
  size = 3)
layer1 + layer2 + layer3
```

```{r layer2}
  layer1 + layer2 + layer3 +
  scale_size(
    "Survivors",
     range = c(1, 10),
     label = label_comma()) + 
  scale_color_manual(
    "Direction",
    values = c("#e5cbaa", "#252020"))
```

```{r layer2}
russia <- ggmap(get_map(
    location = c(left = 22, bottom = 53.5, right = 39, top = 56.5),
    zoom = 6,
    maptype = "toner",
    source = "stamen"))
russia
```

```{r layer2}
russia_layer2 <- geom_path(
  data = troops,
  aes(x = long, y = lat, size = survivors, color = direction, group = division),
  lineend = "square",
  linejoin = "round")

russia + russia_layer2
```

```{r layer2}
russia + russia_layer2 + xlab("") + ylab("") +
  ggtitle("Napoleon's March to Russia") +
  scale_size("Survivors",
             range = c(1, 7),
             label = label_comma()) +
  scale_color_manual(
    "Direction",
    values = c("#e5cbaa", "#252020"))
```