leedrake5 / Russia-Ukraine

Equipment Loss Tracking
MIT License
617 stars 26 forks source link

Plot evolution of tanks lost by type #22

Open gorkang opened 1 year ago

gorkang commented 1 year ago

Thanks for maintaining this repo. It is a fantastic source of information.

I wanted to see the evolution of tanks lost by tank model and created a script using your data. Just wanted to share it with you, in case you are interested in adding an extra plot here.

Cheers.


# Libraries ---------------------------------------------------------------

library(purrr)
library(dplyr)
library(ggplot2)
library(readr)
library(lubridate)
library(furrr)

# Read and compile all non-empty raw daily files  --------------------------

FILES = list.files("data/bySystem/Raw/Daily/", full.names = TRUE)
FILES_size = file.size(list.files("data/bySystem/Raw/Daily/", full.names = TRUE))
FILES_clean = FILES[FILES_size != min(FILES_size)]

plan(multisession, workers = 10)

DF_all =
  1:length(FILES_clean) |> 
  furrr::future_map_dfr(~
        {
          suppressMessages(read_csv(FILES_clean[.x], col_types = cols(.default = "c")) |> mutate(FILE = FILES_clean[.x]))
          }, .progress = TRUE)

# Extract known tanks -----------------------------------------------------

DF = 
  DF_all |> 
  select(country, system, status, Date, sysID) |> 
  mutate(system_simple = 
           case_when(
             grepl("T-90", system) ~ "T90",
             grepl("T-80", system) ~ "T80",
             grepl("T-72", system) ~ "T72",
             grepl("T-64", system) ~ "T64",
             grepl("T-62", system) ~ "T62",
             TRUE ~ "Other"
           )) |> 
  mutate(Date = as.Date(Date, "%m/%d/%Y")) |> 
  mutate(Date_simple = lubridate::floor_date(lubridate::as_date(Date), "month"))

# Create montly counts for plot -------------------------------------------

DF_month = DF |> 
  filter(system_simple %in% c("T90", "T80", "T72", "T64", "T62")) |>
  group_by(country, system_simple, Date_simple) |> 
  summarise(N = n())

# Plot --------------------------------------------------------------------

# Make sure months in plot are in English
Sys.setlocale("LC_TIME","en_GB.UTF-8")

PLOT = DF_month |> 
  ggplot(aes(Date_simple, N, color = system_simple)) +
  geom_point() +
  geom_line() +
  theme_minimal(base_size = 12) +
  scale_x_date(date_breaks = "2 month",
               date_minor_breaks = "1 month", 
               date_labels = "%b %y") +
  scale_y_continuous(n.breaks = 15) +
  facet_grid(~country) +
  guides(color = guide_legend(title = "Tank type")) +
  labs(title = "Tanks abandoned, captured, damaged and destroyed",
       subtitle = "By month and country",
       x = "Date",
       caption = "source: https://github.com/leedrake5/Russia-Ukraine/")

PLOT

ggsave("Plots/tanks_month.png", PLOT, bg = "white", width = 18, height = 10)
leedrake5 commented 1 year ago

Can you put this in a pull request? Easier to integrate and attribution will be to you.