Assignment: Choose six recent popular movies. Ask at least five people that you know (friends, family, classmates,imaginary friends) to rate each of these movie that they have seen on a scale of 1 to 5. Take the results (observations) and store them in a SQL database. Load the information into an R dataframe. #I decided to choose 10 movies instead of 6 to create additional data
#Connect to SQL Database
library(RMySQL)
## Loading required package: DBI
drv <- dbDriver("MySQL")
con <- dbConnect(drv, user = “root”, password = “password”, dbname = “moviedata”, host = “localhost”)
dbListFields(con, "moviedata")
## [1] "participant" "movie" "rating"
query <- "SELECT * FROM moviedata;"
moviedata <- dbGetQuery(con, query)
dbDisconnect(con)
## [1] TRUE
#save as dataframe
completemoviedata <- as.data.frame(moviedata)
completemoviedata
## participant movie rating
## 1 1 Fast and Furious 2
## 2 1 La La Land 1
## 3 1 Get out 1
## 4 1 Fantastic Beasts 4
## 5 1 Cars III 5
## 6 1 Wonder Woman 2
## 7 1 Baby Driver 2
## 8 1 Atomic Blonde 3
## 9 1 Moonlight 1
## 10 1 Manchester by the Sea 1
## 11 2 Fast and Furious 3
## 12 2 La La Land 3
## 13 2 Get out 1
## 14 2 Fantastic Beasts 4
## 15 2 Cars III 3
## 16 2 Wonder Woman 1
## 17 2 Baby Driver 3
## 18 2 Atomic Blonde 3
## 19 2 Moonlight 3
## 20 2 Manchester by the Sea 3
## 21 3 Fast and Furious 5
## 22 3 La La Land 5
## 23 3 Get out 3
## 24 3 Fantastic Beasts 5
## 25 3 Cars III 2
## 26 3 Wonder Woman 4
## 27 3 Baby Driver 2
## 28 3 Atomic Blonde 2
## 29 3 Moonlight 5
## 30 3 Manchester by the Sea 4
## 31 4 Fast and Furious 1
## 32 4 La La Land 1
## 33 4 Get out 1
## 34 4 Fantastic Beasts 2
## 35 4 Cars III 1
## 36 4 Wonder Woman 4
## 37 4 Baby Driver 2
## 38 4 Atomic Blonde 3
## 39 4 Moonlight 2
## 40 4 Manchester by the Sea 4
## 41 5 Fast and Furious 4
## 42 5 La La Land 1
## 43 5 Get out 3
## 44 5 Fantastic Beasts 2
## 45 5 Cars III 5
## 46 5 Wonder Woman 4
## 47 5 Baby Driver 2
## 48 5 Atomic Blonde 2
## 49 5 Moonlight 4
## 50 5 Manchester by the Sea 5
#Create boxplot to show average movie ratings
library(ggplot2)
ggplot(completemoviedata, aes(movie,rating)) +
geom_boxplot() +
ylab("Rating") + theme(axis.text.x = element_text(angle = 90, hjust = 1))+ ggtitle("Average Ratings for Movies")