**Focus**: ggplot2, factors, strings, dates

18. Identify variable(s) which should be factors and transform their type into a factor variable.

19. Create a new variable: Read about `cut_number()` function using Help and add a new variable to the dataset `calories_type`. Use `calories` variable for `cut_number()` function to split it into 3 categories `n=3`, add labels `labels=c("low", "med", "high")` and make the dataset ordered by arranging it according to calories. Do not forget to save the updated dataset.

20. Create a dataviz that shows the distribution of `calories_type` in food items for each type of restaurant. Think carefully about the choice of data viz. Use facets, coordinates and theme layers to make your data viz visually appealing and meaningful. Use factors related data viz functions.

21. Add a new variable that shows the percentage of `trans_fat` in `total_fat` (`trans_fat`/`total_fat`). The variable should be named `trans_fat_percent`. Do not forget to save the updated dataset.

22. Create a dataviz that shows the distribution of `trans_fat` in food items for each type of restaurant. Think carefully about the choice of data viz. Use facets, coordinates and theme layers to make your data viz visually appealing and meaningful.

23. Calculate and show the average (mean) `total_fat` for each type of restaurant. No need to save it as a variable.

24. And create a dataviz that allow to compare different restaurants on this variable (`total_fat`). You can present it on one dataviz (= no facets). Think carefully about the choice of data viz.

Use coordinates and theme layers to make your data viz visually appealing and meaningful. Save your file as .rmd Pull-commit-push it to github

Answer :

18. Variables `type` and `restaurant` should be transformed into factors using the following code:```{r}chew_data$type <- factor(chew_data$type)chew_data$restaurant <- factor(chew_data$restaurant)```19. To create a new variable named `calories_type`, you can use the `cut_number()` function to split the `calories` variable into three categories with labels `low`, `med`, and `high`. This can be done using the following code:```{r}library(dplyr)library(scales)chew_data <- chew_data %>% mutate(calories_type = cut_number(calories, n = 3, labels = c("low", "med", "high"), ordered = TRUE))```20.

To create a data visualization showing the distribution of `calories_type` in food items for each type of restaurant, you can use a bar plot with facets for each type of restaurant.```{r}library(ggplot2)ggplot(chew_data, aes(x = calories_type, fill = restaurant)) + geom_bar() + facet_wrap(~ type, nrow = 2) + theme_bw()```21. To create a new variable named `trans_fat_percent` that shows the percentage of `trans_fat` in `total_fat`, you can use the following code:```{r}chew_data$trans_fat_percent <- chew_data$trans_fat / chew_data$total_fat```22. To create a data visualization showing the distribution of `trans_fat` in food items for each type of restaurant, you can use a box plot with facets for each type of restaurant.

```{r}ggplot(chew_data, aes(x = restaurant, y = trans_fat_percent)) + geom_boxplot() + facet_wrap(~ type, nrow = 2) + theme_bw()```23. To calculate and show the average `total_fat` for each type of restaurant, you can use the following code:```{r}chew_data %>% group_by(restaurant, type) %>% summarize(mean_total_fat = mean(total_fat))```24. To create a data visualization allowing comparison of different restaurants on the variable `total_fat`, you can use a dot plot with the size of the dots indicating the value of `mean_total_fat` and the color of the dots indicating the type of restaurant.```{r}mean_total_fat <- chew_data %>% group_by(restaurant, type) %>% summarize(mean_total_fat = mean(total_fat))ggplot(mean_total_fat, aes(x = restaurant, y = mean_total_fat, size = mean_total_fat, color = type)) + geom_point() + theme_bw()```

To know more about restaurant visit:-

https://brainly.com/question/31921567

#SPJ11