Loading the required library
library(RMySQL)
## Loading required package: DBI
library(DBI)
Establishing a connection with MySQL Server
drv<-dbDriver("MySQL")
con <- dbConnect(drv, user="root", password="abcd", host="127.0.0.1", port=3306, dbname="movies")
Loading the two data tables separately in R
movies <- dbGetQuery(con, "SELECT moviesID AS ID,
moviesName AS Title,
Genre AS Genre
FROM movies")
ratings<- dbGetQuery(con, ("SELECT * FROM ratin"))
Combining the two tables using JOIN to show all columns
combined<-as.data.frame(dbGetQuery(con, ("SELECT * FROM movies
NATURAL JOIN ratin")))
Check the table and summary statistics of rating
dim(combined)
## [1] 30 5
combined[1:10,]
## moviesID moviesName Genre Friend rating
## 1 1 Brightburn Action John 1
## 2 1 Brightburn Action Moureen 3
## 3 1 Brightburn Action Nausher 2
## 4 1 Brightburn Action Kimu 1
## 5 1 Brightburn Action Imran 4
## 6 2 Batman returns Action John 5
## 7 2 Batman returns Action Moureen 4
## 8 2 Batman returns Action Nausher 5
## 9 2 Batman returns Action Kimu 3
## 10 2 Batman returns Action Imran 3
summary(combined$rating)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 2.250 4.000 3.433 5.000 5.000
library("ggplot2")
library("grid")
ggplot(combined, aes(x=Friend, y=rating))+
geom_boxplot(fill="LightBlue")+
ggtitle("How my friends rate")
How my friends have rated different genres My friends prefer Drama and Horror over Action!
ggplot(combined,aes(x=Genre, y=rating) )+
geom_boxplot(fill="LightBlue")+
ggtitle("How my friends rated different genres")
The frequency of the ratings
ggplot(combined,aes(x=rating))+
geom_bar(fill="LightBlue")+
ggtitle("Frequency of ratings")