Read, Row-Bind, Summarize & Visualize Multiple Data Sets in R | tidyverse, readr, dplyr & ggplot2

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024
  • How to import, combine, summarize, and visualize two data sets in the R programming language. More details: statisticsglob...
    The video analyzes group participants of the "Data Manipulation in R Using dplyr & the tidyverse" online course. More details here: statisticsglob...
    R code of this video:
    install.packages("tidyverse") # Install & load tidyverse package
    library("tidyverse")
    my_path <- "C:/Users/Joach/Desktop/my project/" # Specify working directory
    data1 <- read_csv(str_c(my_path, "data1.csv")) # Import first data set
    data1 # Print first data set
    data2 <- read_csv(str_c(my_path, "data2.csv")) # Import second data set
    data2 # Print second data set
    data1_upd <- data1 %>% # Filter rows
    filter(! ID %in% c("ID5", "ID13", "ID55"))
    data1_upd
    data_all <- data1_upd %>% # Row-bind multiple data sets
    bind_rows(data2)
    head(data_all) # Head of combined data
    tail(data_all) # Tail of combined data
    nrow(data_all) # Total number of participants
    data_summ <- data_all %>% # Convert vector to tibble
    group_by(country) %>% # Group tibble
    summarize(country_count = n()) %>% # Calculate country count
    arrange(desc(country_count)) # Arrange tibble descendingly
    data_summ # Print country data
    data_summ %>% # Create ggplot2 plot
    ggplot(aes(x = reorder(country, - country_count),
    y = country_count)) +
    geom_col() + # Specify to draw a barplot
    theme(axis.text.x = element_text(angle = 90, # Vertical x-axis labels
    hjust = 1,
    vjust = 0.3)) +
    xlab("Country") + # Change x-axis label
    ylab("Count") + # Change y-axis label
    annotate("text", # Add text element to plot
    x = 15,
    y = 25,
    label = "Course Participants
    by Country",
    size = 15,
    color = "#1b98e0")
    Follow me on Social Media:
    Facebook - Statistics Globe Page: / statisticsglobecom
    Facebook - R Programming Group for Discussions & Questions: / statisticsglobe
    Facebook - Python Programming Group for Discussions & Questions: / statisticsglobepython
    LinkedIn - Statistics Globe Page: / statisticsglobe
    LinkedIn - R Programming Group for Discussions & Questions: / 12555223
    LinkedIn - Python Programming Group for Discussions & Questions: / 12673534
    Twitter: / joachimschork
    Instagram: / statisticsglobecom
    TikTok: / statisticsglobe

Комментарии • 12