LAB2_A

Author

Reginald Dorcely

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars} movie_data <- data.frame( person = c( “Alice”,“Alice”,“Alice”,“Alice”,“Alice”, “Brian”,“Brian”,“Brian”,“Brian”,“Brian”, “Carla”,“Carla”,“Carla”,“Carla”,“Carla”, “David”,“David”,“David”,“David”,“David”, “Elena”,“Elena”,“Elena”,“Elena”,“Elena” ),

movie = c( “Spider-Man: Brand New Day”,“The Odyssey”,“Toy Story 5”, “The Super Mario Galaxy Movie”,“Project Hail Mary”,

"Spider-Man: Brand New Day","The Odyssey","Toy Story 5",
"The Super Mario Galaxy Movie","Project Hail Mary",

"Spider-Man: Brand New Day","The Odyssey","Toy Story 5",
"The Super Mario Galaxy Movie","Project Hail Mary",

"Spider-Man: Brand New Day","The Odyssey","Toy Story 5",
"The Super Mario Galaxy Movie","Project Hail Mary",

"Spider-Man: Brand New Day","The Odyssey","Toy Story 5",
"The Super Mario Galaxy Movie","Project Hail Mary"

),

rating = c( 5,4,4,5,4, 4,5,3,4,5, 5,4,5,4,4, 3,5,4,5,5, 4,4,5,4,3 ) ) View(movie_data) library(ggplot2) library(dplyr)

Calculate average rating for each movie

movie_summary <- movie_data %>% group_by(movie) %>% summarise( average_rating = mean(rating) )

View summary

movie_summary

Create bar graph

ggplot(movie_summary, aes(x = reorder(movie, average_rating), y = average_rating)) + geom_col() + coord_flip() + labs( title = “Average Ratings for Five Popular Movies”, x = “Movie”, y = “Average Rating” ) + ylim(0, 5) ggplot(movie_summary, aes(x = movie, y = average_rating)) + geom_col() + labs( title = “Average Movie Ratings”, x = “Movie”, y = “Average Rating” ) + ylim(0, 5) + theme( axis.text.x = element_text( angle = 45, hjust = 1 ) )

The echo: false option disables the printing of code (only output is displayed).