Question: Which of the top movies in 2018 was liked by the target audience
Audience
1) Friend
2) Family
3) Classmate
4) Imaginery Friend
Create connection to MySQL
con = dbConnect(MySQL(), user= "root", host= "localhost", password= "cuny", dbname= "movie", port= 3306)
Create a table in R from MYSQL
query <- "select * from movie;"
df <- dbGetQuery(con,query)
str(df)
## 'data.frame': 24 obs. of 4 variables:
## $ ID : int 1 1 1 1 2 2 2 2 3 3 ...
## $ Movie : chr "Annihilation" "Annihilation" "Annihilation" "Annihilation" ...
## $ People: chr "Friend" "Family" "Classmate" "Imaginery friend" ...
## $ rate : int 5 3 4 5 5 5 5 5 5 2 ...
Group Movie and the calculate average movie rate
table <- df %>% group_by(Movie) %>% summarize(average = mean(rate))
table
## # A tibble: 6 x 2
## Movie average
## <chr> <dbl>
## 1 Annihilation 4.25
## 2 Black Panther 5
## 3 Dead Pool 4
## 4 Game Night 3.75
## 5 Incredibles 4.25
## 6 Star Wars 3
Plot the results to reflect the movie that is rated highest on average
ggplot(table, aes(x= Movie,y = average)) +
geom_bar(stat = "identity") +
coord_flip()

Conclusion
It appears that the Black Panther was the best movie for 2018 for the target population.