myData <-read_csv ("../00_data/myData.csv")
## Rows: 27 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): film, film_rating
## dbl (2): number, run_time
## date (1): release_date
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
myData%>% count(film_rating)
## # A tibble: 4 × 2
## film_rating n
## <chr> <int>
## 1 G 13
## 2 N/A 3
## 3 Not Rated 1
## 4 PG 10
film_levels <- c("G","PG","N/A")
myData_rev<- myData%>%
mutate(film_rating= film_rating%>% factor(levels = film_levels))
Make two bar charts here - one before ordering another after
myData_summary <- myData %>%
group_by(film_rating) %>%
summarise(
run_time = mean(run_time, na.rm = TRUE))
ggplot(myData_summary, aes(run_time, fct_reorder(film_rating, run_time))) + geom_point()
Show examples of three functions:
myData%>%
mutate(film_rating= fct_recode(film_rating,
"GeneralAudience" = "G",
"ParentalGuidance" = "PG",
"NotApplicable" = "N/A",
"NoRating" = "Not Rated")) %>%
count(film_rating)
## # A tibble: 4 × 2
## film_rating n
## <fct> <int>
## 1 GeneralAudience 13
## 2 NotApplicable 3
## 3 NoRating 1
## 4 ParentalGuidance 10
myData%>%
mutate(film_rating = fct_collapse(film_rating,
GeneralAudience = "G",
Other = c("PG","N/A","Not Rated")))%>%
count(film_rating)
## # A tibble: 2 × 2
## film_rating n
## <fct> <int>
## 1 GeneralAudience 13
## 2 Other 14
myData%>%
mutate(film_rating = fct_lump(film_rating))%>%
count(film_rating)
## # A tibble: 3 × 2
## film_rating n
## <fct> <int>
## 1 G 13
## 2 PG 10
## 3 Other 4
No need to do anything here.