1. Load all the required libraries
library(getPass)
library(RMySQL)
library(tidyverse)
library(plotly)
2. Connect to MySQL and save the data
connection <-dbConnect(MySQL(),
user=getPass(msg = "username: "),
password=getPass(msg = "password: "),
dbname="movies",
host='localhost'
)
## Please enter password in TK window (Alt+Tab)
## Please enter password in TK window (Alt+Tab)
movies_rating <- as.data.frame(dbGetQuery(connection,'select * from movies_rating;'))
3. Summarize the data
mo_tidy <- movies_rating %>%
spread(Movie,Rating)
summary(mo_tidy)
## Name A Star is Born Aquaman Bird Box Bumblebee
## Length:5 Min. :3.0 Min. :3.0 Min. :2.0 Min. :3
## Class :character 1st Qu.:4.5 1st Qu.:4.0 1st Qu.:3.0 1st Qu.:3
## Mode :character Median :5.0 Median :4.0 Median :3.0 Median :4
## Mean :4.5 Mean :4.2 Mean :3.2 Mean :4
## 3rd Qu.:5.0 3rd Qu.:5.0 3rd Qu.:4.0 3rd Qu.:5
## Max. :5.0 Max. :5.0 Max. :4.0 Max. :5
## NA's :1
## First Man Ralph Breaks the Internet: Wreck-It Ralph 2
## Min. :2.00 Min. :3.0
## 1st Qu.:2.75 1st Qu.:3.5
## Median :3.50 Median :4.0
## Mean :3.50 Mean :4.0
## 3rd Qu.:4.25 3rd Qu.:4.5
## Max. :5.00 Max. :5.0
## NA's :1 NA's :2
4. Visiualize the average rating of each movies
rating_mean <- movies_rating %>%
na.omit()%>%
group_by(Movie) %>%
summarise(Rating = mean(Rating))
avg_plot <- rating_mean %>%
ggplot(aes(x = Movie,y = Rating,fill=Movie))+
geom_bar(stat = "identity")+
labs(title = "Average Rating of the Movies")+
xlab("")+
ylab("Rating")+
theme(axis.text.x = element_text(angle = 15, hjust = 1),
legend.position='none')
ggplotly(avg_plot)
5. Take a look from the boxplot
mov_bp <- movies_rating %>%
group_by(Movie) %>%
ggplot(aes(x = Movie,y = Rating,fill=Movie))+
geom_boxplot()+
labs(title = "Rating of the Movies")+
xlab("")+
ylab("Rating")+
theme(axis.text.x = element_text(angle = 15, hjust = 1),
legend.position='none')
ggplotly(mov_bp)