Total Deaths vs Military Deaths (Top 10 Countries)

Code for previous slide

df = read.csv("C:\\Users\\josem\\OneDrive\\Documents\\DAT301\\HW3\\ww2_data - ww2_deaths.csv", sep=",", header=TRUE)
dfTop10 <- df %>%
  arrange(desc(Total_deaths)) %>%
  slice(1:10)
mod = lm(Total_deaths ~ Military_Deaths, data = dfTop10)
x = dfTop10$Military_Deaths; y = dfTop10$Total_deaths
countryNames = dfTop10$Country
xax <- list(
  Title = "Military Deaths",
  titlefont = list(family= "Modern Computer Roman")
)
yax <- list(
  Title = "Total Deaths",
  titlefont = list(family= "Modern Computer Roman")
)
fig <- plot_ly(x=x, y=y, type = "scatter", mode = "markers",text = countryNames, hoverinfo = "text", name ="Deaths", width = 800, height = 430) %>%
  add_lines(x=x, y = fitted(mod), name = "fitted") %>%
  layout(xaxis = xax, yaxis = yax) %>%
  layout(margin = list(
  l = 150,
  r=50,
  b=20,
  t = 40
  ))

Civilian Deaths

Total Deaths

Average Deaths Europe

\[ \text{Average Deaths in Europe} = \frac{\text{ Total European Deaths}}{\text{Total European Countries}} \]

library(countrycode)
df$Continent = countrycode(sourcevar = df$Country,
                            origin = "country.name",
                            destination = "continent")
df[df$Country == "Yugoslavia", "Continent"] <- "Europe"
df[df$Country == "Czechoslovakia", "Continent"] <- "Europe"
df[df$Country == "Dutch East Indies", "Continent"] <- "Asia"
df[df$Country == "Malaya", "Continent"] <- "Asia"
dfEurope = df[df$Continent == "Europe", ]
avgEuropeDeaths = mean(dfEurope$Total_deaths, na.rm = TRUE)
print(paste("Average Deaths: ", as.integer(avgEuropeDeaths)))

[1] “Average Deaths: 1956652”

Average Deaths Asia

\[ \text{Average Deaths in Asia} = \frac{\text{ Total Asian Deaths}}{\text{Total Asian Countries}} \]

library(countrycode)
df$Continent = countrycode(sourcevar = df$Country,
                            origin = "country.name",
                            destination = "continent")
df[df$Country == "Yugoslavia", "Continent"] <- "Europe"
df[df$Country == "Czechoslovakia", "Continent"] <- "Europe"
df[df$Country == "Dutch East Indies", "Continent"] <- "Asia"
df[df$Country == "Malaya", "Continent"] <- "Asia"
dfAsia = df[df$Continent == "Asia", ]
avgAsiaDeaths = mean(dfAsia$Total_deaths, na.rm = TRUE)
print(paste("Average Deaths: ", as.integer(avgAsiaDeaths)))

[1] “Average Deaths: 3635888”

Civilian Deaths vs Military Deaths