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