Analysing my achievements for the year 2024 in my different habits.
Code
# Loading the relevant packageslibrary(tidyverse) # Data Wranglinglibrary(gt) # Displaying beautiful tableslibrary(ggiraph) # Interactive Graphicslibrary(showtext) # Display fancy text in ggplot2library(fontawesome) # Icons and Fonts # Setting font defaultsfont_add_google("Monda", "body_font")showtext_auto()# Set the default theme with a custom font familytheme_set(theme_minimal(base_family ="body_font"))# Setting default options for the interactive graphicsset_girafe_defaults(opts_hover =opts_hover(css ="fill:yellow;stroke:black;stroke-width:1px" ),opts_tooltip =opts_tooltip(css ="padding:3px;color:black;background-color:white;" ))
Loading the data, studying and understanding it. Cleaning the names.
Code
# Set the working directory (I didnt want to host raw data on GitHub)list.files("loop_habits")# Define the directory containing the CSV filesdirectory <-"loop_habits"# List all CSV files in the directorycsv_files <-list.files(path = directory, pattern ="\\.csv$", full.names =TRUE )# Extract base names (without file extension) to use as object namesfile_names <- tools::file_path_sans_ext(basename(csv_files)) |>tolower()# Read each CSV file and assign it to an object with the corresponding namepurrr::walk2( csv_files, file_names, ~assign(.y, read_csv(.x), envir = .GlobalEnv) )library(janitor)# Apply janitor::clean_names() to all created objectspurrr::walk( file_names, ~ { cleaned_data <-get(.x) |>clean_names() # Retrieve object, clean namesassign(.x, cleaned_data, envir = .GlobalEnv) # Reassign cleaned data back to the same object } )# Remove the temporary filesrm(csv_files, directory, file_names)
Exploring the raw data in the root folder - the overall habits - to make a beautiful table in {gt} tables