Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot evolution of tanks lost by type #22

Open
gorkang opened this issue May 25, 2023 · 1 comment
Open

Plot evolution of tanks lost by type #22

gorkang opened this issue May 25, 2023 · 1 comment

Comments

@gorkang
Copy link

gorkang commented May 25, 2023

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants