Skip to content

Commit

Permalink
Create ua-pop-2022-andriy.R
Browse files Browse the repository at this point in the history
#19 @Tytser , please see my graph and incorporate it if you think it's useful
  • Loading branch information
andkov committed Sep 2, 2022
1 parent 4b01856 commit dba1c4d
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions analysis/ua-pop-2022/ua-pop-2022-andriy.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
rm(list = ls(all.names = TRUE)) # Clear the memory of variables from previous run. This is not called by knitr, because it's above the first chunk.
cat("\014") # Clear the console
# verify root location
cat("Working directory: ", getwd()) # Must be set to Project Directory
# Project Directory should be the root by default unless overwritten

# ---- load-packages -----------------------------------------------------------
# Choose to be greedy: load only what's needed
# Three ways, from least (1) to most(3) greedy:
# -- 1.Attach these packages so their functions don't need to be qualified: http://r-pkgs.had.co.nz/namespace.html#search-path
library(ggplot2) # graphs
library(forcats) # factors
library(stringr) # strings, but consider `stringi` as more general
library(lubridate) # dates
library(labelled) # labels
library(dplyr) # data wrangling
# -- 2.Import only certain functions of a package into the search path.
import::from("magrittr", "%>%")
# -- 3. Verify these packages are available on the machine, but their functions need to be qualified: http://r-pkgs.had.co.nz/namespace.html#search-path
requireNamespace("readr" )# data import/export
requireNamespace("readxl" )# data import/export
requireNamespace("tidyr" )# tidy data
requireNamespace("janitor" )# tidy data
requireNamespace("testit" )# for asserting conditions meet expected patterns.
requireNamespace("scales" )# formatting

# ---- load-sources ------------------------------------------------------------
base::source("./scripts/common-functions.R") # project-level

# ---- declare-globals ---------------------------------------------------------
Sys.setlocale("LC_CTYPE", "ukr")
# printed figures will go here when `quick_save("name",w=8,h=6)` is used:
prints_folder <- paste0("./analysis/ua-pop-2022/prints/")
if (!fs::dir_exists(prints_folder)) { fs::dir_create(prints_folder) }

path_data_input <- "./data-public/derived/ua-pop-2022.csv"
# ---- declare-functions -------------------------------------------------------

# ---- load-data ---------------------------------------------------------------
ds0 <- readr::read_csv(path_data_input)

ds0 %>% glimpse()
ds0
# ---- inspect-data ------------------------------------------------------------


# ---- tweak-data --------------------------------------------------------------


# ---- table-1 -----------------------------------------------------------------

d1 <-
ds0 %>%
group_by(oblast) %>%
summarize(
person_count = sum(Persons, na.rm = T)
)
d1 %>% neat()
# ---- graph-1 -----------------------------------------------------------------

g1 <-
d1 %>%
{
ggplot(
.
,aes(
x = person_count
,y = oblast
)
)+
geom_col()+
labs(title = "Населення областей України у 2022")
}
g1
g1 %>% quick_save("1-oblast", w=3, h=8)

# ---- graph-2 -----------------------------------------------------------------

# ---- save-to-disk ------------------------------------------------------------

# ---- publish ------------------------------------------------------------
path <- "./analysis/ua-pop-2022/ua-pop-2022.Rmd" # connect with Rmd for publishing
rmarkdown::render(
input = path ,
output_format=c(
"html_document"
# "word_document"
# "pdf_document"
),
clean=TRUE
)

0 comments on commit dba1c4d

Please sign in to comment.