How to Import, Manipulate & Visualize Data Using the tidyverse in R | readr, dplyr & ggplot2 Package

preview_player
Показать описание


R code of this video:

library("tidyverse") # Load tidyverse packages

my_path <- "D:/Dropbox/Jock/Data Sets/" # Specify directory path

tib_dest <- read_csv(str_c(my_path, # Import CSV file
tib_dest # Print tibble

tib_dest %>% # Class of data set
class()

tib_dest %>% # Show entire data set
View()

tib_dest_new <- tib_dest %>% # Rename column
rename(T2019 = `International tourist arrivals (2019)`)
tib_dest_new # Print updated tibble

tib_dest_new2 <- tib_dest_new %>% # Remove certain columns
select(- ...1, - `International tourist arrivals (2018)`)
tib_dest_new2 # Print updated tibble

tib_dest_new3 <- tib_dest_new2 %>% # Replace values
mutate(across(everything(), ~ replace(., . == "–", NA)),
tib_dest_new3 # Print updated tibble

tib_dest_new4 <- tib_dest_new3 %>% # Remove NA rows
tib_dest_new4 # Print updated tibble

tib_dest_new5 <- tib_dest_new4 %>% # Remove duplicate row
filter(Destination != "Egypt" | Region == "Africa")
tib_dest_new5 # Print updated tibble

my_ggp <- tib_dest_new5 %>% # Create ggplot2 plot
mutate(Destination = reorder(Destination, - T2019)) %>%
ggplot(aes(x = Destination,
y = T2019,
fill = Region)) +
geom_col() +
hjust = 1,
vjust = 0.5))
my_ggp # Draw ggplot2 plot

tib_dest %>% # Do all at once
rename(T2019 = `International tourist arrivals (2019)`) %>%
select(- ...1, - `International tourist arrivals (2018)`) %>%
mutate(across(everything(), ~ replace(., . == "–", NA)),
filter(Destination != "Egypt" | Region == "Africa") %>%
mutate(Destination = reorder(Destination, - T2019)) %>%
ggplot(aes(x = Destination,
y = T2019,
fill = Region)) +
geom_col() +
hjust = 1,
vjust = 0.25))

Follow me on Social Media:
Рекомендации по теме
Комментарии
Автор

always can learn new useful things from this channel.

nedlin
Автор

thank, how to change the first column to the name of the school? Thanks for the answer.

dedisetiawan
Автор

Can you please tell me how to add features in r studio my data is full of website in need to find is it malicious or benign

mayankpatel