/ Python And R Data science skills: 04/24/18

Tuesday 24 April 2018

26 home work in ggplot movie Gross Telugu

----------------
movie<-read.csv("movie.csv")

head(movie)
summary(movie)
str(movie)
library(ggplot2)
ggplot(data=movie,aes(x=Day.of.Week))+
  geom_bar()
# filtering data frame
filter1<-(movie$Genre=="action")|(movie$Genre=="adventure")|
  (movie$Genre=="animation")|(movie$Genre=="comedy")|
  (movie$Genre=="drama")
filter1
filter2<-movie$Studio %in% c("Buena Vista Studios","WB","Fox","Universal","Sony","Paramount Pictures")     
filter2
movie2<-movie[filter1 & filter2,]
movie2
tail(movie2)
vlr<-ggplot(data=movie2,aes(x=Genre,y=Gross...US))
vlr + geom_jitter()+
  geom_boxplot()

#use alpah
vlr + geom_jitter()+
  geom_boxplot(alpha=.7)
# use color and size
vlr + geom_jitter(aes(size=Budget...mill.,
                      color=Studio))+
  geom_boxplot(alpha=0.7)
# change block dots
vlr + geom_jitter(aes(size=Budget...mill.,
                      color=Studio))+
  geom_boxplot(alpha=0.7,outlier.colour = NA)

vlr1<- vlr + geom_jitter(aes(size=Budget...mill.,
                             color=Studio))+
  geom_boxplot(alpha=0.5,outlier.colour = NA)
vlr1
vlr1 +
  xlab("Genre")+
  ylab("Gross % Us")+
  ggtitle("Domestic Gross % by Genre")+
  theme(
    axis.title.x = element_text(color="Blue",size=10),
    axis.title.y = element_text(color="Blue",size=10),
   
    axis.text.y = element_text(size=10),
    axis.text.x = element_text(size=10),
    plot.title = element_text(size=20),
   
    legend.title = element_text(size=20),
    legend.text = element_text(size=20),
   
   
  )






25 limits and theme settings in R language


---------------------------------------
movie<-read.csv("Movie-Ratings.csv")
colnames(movie)<-c("Film","Genre","CriRating",
                   "AudRatining","BMill","Year")

movie$Year<-factor(movie$Year)
head(movie)
summary(movie)
library(ggplot2)
r<- ggplot(data=movie,
           aes(x=CriRating,y=AudRatining,
               color=Genre,
               size=BMill))
r + geom_point()
# movies with higest rating
#limits
r + geom_point() +
  xlim(50,100)+
  ylim(50,100)
r + geom_point() +
  xlim(1,50)+
  ylim(1,50)

r + geom_point() +
 coord_cartesian(ylim = c(1,50),
                 xlim = c(1,50))
r + geom_point() +
  coord_cartesian(ylim = c(80,100),
                  xlim = c(80,100))
# theme
r<- ggplot(data=movie,
           aes(x=BMill))
r + geom_histogram(binwidth = 10,
                   aes(fill=Genre),
                   color="Black")

k <- r + geom_histogram(binwidth = 10,
                        aes(fill=Genre),
                        color="Black")
k
k +
  xlab("Budget Money")+
  ylab("number Of Movies")
#####
k +
  xlab("Budget Money")+
  ylab("number Of Movies")+
  theme(axis.title.x = element_text(color = "Green",size=30),
        axis.title.y = element_text(color = "red",size=30)
        )

?theme

k +
  xlab("Budget Money")+
  ylab("number Of Movies")+
  theme(axis.title.x = element_text(color = "Green",size=30),
        axis.title.y = element_text(color = "red",size=30),
        legend.title = element_text(size=30),
        legend.text = element_text(size=20),
        legend.position = c(1,1)
  )

k +
  xlab("Budget Money")+
  ylab("number Of Movies")+
  theme(axis.title.x = element_text(color = "Green",size=30),
        axis.title.y = element_text(color = "red",size=30),
        legend.title = element_text(size=30),
        legend.text = element_text(size=20),
        legend.position = c(1,1),
        legend.justification = c(1,1)
  )
k +
  xlab("Budget Money")+
  ylab("number Of Movies")+
  ggtitle("Movie Budget Graph")+
  theme(axis.title.x = element_text(color = "Green",size=30),
        axis.title.y = element_text(color = "red",size=30),
        legend.title = element_text(size=30),
        legend.text = element_text(size=20),
        legend.position = c(1,1),
        legend.justification = c(1,1)
  )
#####
k +
  xlab("Budget Money")+
  ylab("number Of Movies")+
  ggtitle("Movie Budget Graph")+
  theme(axis.title.x = element_text(color = "Green",size=30),
        axis.title.y = element_text(color = "red",size=30),
        legend.title = element_text(size=30),
        legend.text = element_text(size=20),
        legend.position = c(1,1),
        legend.justification = c(1,1),
        plot.title = element_text(color="darkred",size=30,
                                  family="Courier")
  )

24 Box plot r language telugu

--------------------------------
movie<-read.csv("Movie-Ratings.csv")
colnames(movie)<-c("Film","Genre","CriRating",
                   "AudRatining","BMill","Year")

movie$Year<-factor(movie$Year)
head(movie)
summary(movie)
library(ggplot2)
r<- ggplot(data=movie,
           aes(x=CriRating,y=AudRatining,color=Genre))
r

r + geom_point()
r + geom_point()+ geom_smooth()
r + geom_point()+ geom_smooth(fill=NA)
#boxplot
r<- ggplot(data=movie,
           aes(x=Genre,y=AudRatining,color=Genre))
r + geom_boxplot()

r + geom_boxplot(size = 1.2)

r + geom_boxplot(size = 1.2) +
  geom_point()
r + geom_boxplot(size = 1.2) +
  geom_jitter()
#facets
r<- ggplot(data=movie,
           aes(x=BMill))
r +geom_histogram(binwidth = 10,
                  aes(fill=Genre),
                  color="Black")

r +geom_histogram(binwidth = 10,
                  aes(fill=Genre),
                  color="Black")+
  facet_grid(Genre~.)
r +geom_histogram(binwidth = 10,
                  aes(fill=Genre),
                  color="Black")+
  facet_grid(Genre~.,scale="free")
###
z<- ggplot(data=movie,
           aes(x=CriRating,y=AudRatining,color=Genre))

z+geom_point(size=1)+
  facet_grid(Genre~.)
z+geom_point(size=1)+
  facet_grid(.~Year)

z+geom_point(size=1)+
  facet_grid(Genre~Year)

z+geom_point(size=1)+
  geom_smooth()+
  facet_grid(Genre~Year)
z+geom_point(aes(size=BMill))+
  geom_smooth()+
  facet_grid(Genre~Year)

23 histograms in ggplot R language Telugu


-----------------------------------------

movie<-read.csv("Movie-Ratings.csv")
colnames(movie)<-c("Film","Genre","CriRating",
                   "AudRatining","BMill","Year")

movie$Year<-factor(movie$Year)
head(movie)
summary(movie)
library(ggplot2)



######## mapping and setting
r<- ggplot(data=movie,
           aes(x=CriRating,y=AudRatining))
r

r + geom_point()

######## mapping
r + geom_point(aes(color=Genre))
r + geom_point(aes(color="DarkGreen"))
#Setting
r + geom_point(color="DarkGreen")

r + geom_point(aes(size=BMill))
r + geom_point(size=BMill)
r + geom_point(size=5)
r + geom_point(aes(size=25))
# Histogram and density Charts
s<- ggplot(data=movie,
           aes(x=BMill))
s+geom_histogram()
s+geom_histogram(binwidth=20)
s+geom_histogram(binwidth=10,fill="Green")
s+geom_histogram(binwidth=10,aes(fill=Genre))
s+geom_histogram(binwidth=10,aes(fill=Genre),
                 color="black")
s+geom_density()
s+geom_density(aes(fill=Genre))   
s+geom_density(aes(fill=Genre),position = "stack")             
###############
t <- ggplot(data=movie)
t + geom_histogram(binwidth=10,
                   aes(x=AudRatining),
                   fill="white",
                   color="Blue")
t + geom_histogram(binwidth=10,
                   aes(x=CriRating),
                   fill="white",
                   color="Blue")

22 multi layers in ggplot in r language Telugu


----------------------------------------------
movie<-read.csv("Movie-Ratings.csv")
colnames(movie)<-c("Film","Genre","CriRating","AudRatining","BMill","Year")

movie$Year<-factor(movie$Year)
head(movie)
summary(movie)
library(ggplot2)


ggplot(data=movie,
       aes(x=CriRating,y=AudRatining,color=Genre,
           size=BMill)) +
  geom_point()
Myp<-ggplot(data=movie,
            aes(x=CriRating,y=AudRatining,color=Genre,
                size=BMill))

Myp
Myp + geom_point()
Myp + geom_line()
Myp + geom_point() + geom_line()

#########
Myp +geom_point(aes(size=CriRating))
Myp +geom_point(aes(color=BMill,size=CriRating))
Myp +geom_point(aes(color=BMill,size=AudRatining))
Myp +geom_point(aes(x=BMill))+
  xlab("Budget in Milion")
Myp + geom_point() + geom_line()
Myp + geom_point() + geom_line(size=.4)