Chapter : Data Visualization : Part 1

#AGENDA:
#Basic R Graphics
#Grammar of Graphics
#GGPLOT2
#In this slide I will cover Base Graphics
#Basic Graphics helps us to make simple 2d graphs
#Dataset Used : IRIS data.frame
data("iris")
head(iris)
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
## 3          4.7         3.2          1.3         0.2  setosa
## 4          4.6         3.1          1.5         0.2  setosa
## 5          5.0         3.6          1.4         0.2  setosa
## 6          5.4         3.9          1.7         0.4  setosa
#common Arguments :
#
#xlab : X label of x axis
#ylab : y label of y axis
#main : Title of Graph
#col : Colour of points/bars/boxPlots
#1 ScatterPlot : It is used for bivariate analysis
#Function used : plot(x~y)
#Argument : pch = value it determines the shape of plots
plot(iris$Sepal.Length~iris$Petal.Length,ylab = "Petal Length", xlab = "Sepal Length", main="Sepal Length versus Petal Length", col = "blue",pch = 16)

#2 Histogram
#It is used for univariate analysis
#Converts data into freqency
#It can be plotted as numbers or percentage
#Nature of data : Unimodal Distribution, Bimodal Distribution, Multimodal Distribution
#Caveat(Warning): Data must be of same distribution
#Function Used : hist(x)
hist(iris$Sepal.Width,xlab = "Sepal Width",ylab = "Frequency", main="Histogram showing freqency w.r.t. Sepal Width in Iris DataSet", col="aquamarine3")

#3 BoxPlot
#It is used to determine how does continuos variable change W.r.t. a categorical variable
# Sepal.Length = Quantitative Continuous
# Sepal.Width = Quantitative Continuous
# Petal.Length = Quantitative Continuous
#Petal.Width = Quantitative Continuous
# Species = Categorical Nominal
#Function Used : boxplot(x~y)
# X axis -> Continuous Variable
# Y axis -> Categorical Variable
boxplot(iris$Sepal.Length~iris$Species,xlab="Species",ylab= "Sepal Length",col = "bur lywood", main = "Sepal Length of Different Species")

#Issues with Base Graphics
#or
#Need of GGPLOT Package
#Print Quality : If ever we want to publish these plots for an international Journal or an international presentation then that would not be possible
#If we want to add levels over these graphs that is not possible with R plots.
##GGPLOT : Here GG stands for Grammar of Graphics so our next step is to understand Grammar of Graphics