Basics of R- Session 6- Data Visualization -1 library ggplot2
Dr Manohar Kapse
19 March 2019
Use Libraries graphics and ggplot
library(graphics)
library(ggplot2)
#Import the file- MBAdata.csv and save as an R object mbaper
# import the file from the location-
mbaper<-read.csv("D:/1 Teaching Material/R/importfile/MBAdata.csv")
# study the data which is imported
str(mbaper)
## 'data.frame': 273 obs. of 19 variables:
## $ Age_in_years_completed : int 23 21 23 25 22 26 24 22 22 26 ...
## $ Percentage_in_10_Class : num 75 68 89.3 71.7 91.2 ...
## $ Percentage_in_12_Class : num 74 78 84.6 90 91.2 ...
## $ Percentage_in_Under_Graduate : num 67 65 66.4 73 70 ...
## $ Gender : Factor w/ 2 levels "Female","Male": 2 1 2 1 1 1 1 2 2 2 ...
## $ STATE : Factor w/ 10 levels "Central Zone",..: 6 6 6 6 1 1 1 1 1 1 ...
## $ Previous_Degree : Factor w/ 6 levels "Arts","Commerce",..: 2 2 3 2 2 3 3 3 3 3 ...
## $ Fathers_qualification : Factor w/ 9 levels "CA/CS","DIPLOMA",..: 2 9 9 9 9 5 7 7 9 9 ...
## $ Mothers_qualification : Factor w/ 7 levels "DIPLOMA","HSC",..: 1 6 2 7 5 5 2 7 7 7 ...
## $ Fathers_occupation : Factor w/ 7 levels "Farming","Not Alive",..: 4 6 5 7 4 2 4 4 4 7 ...
## $ Mothers_occupation : Factor w/ 4 levels "House wife","Professional Job",..: 2 1 1 1 2 1 1 2 1 1 ...
## $ Marital_status : Factor w/ 2 levels "Married","Single": 2 2 2 2 2 1 2 2 2 2 ...
## $ Place_you_belong_to : Factor w/ 3 levels "Rural","Semi Urban",..: 3 1 2 3 3 3 3 2 3 2 ...
## $ Total_Family_Income_per_annum : Factor w/ 6 levels "0-3 Lakh","10-15 lakh",..: 6 2 4 2 4 1 2 6 6 3 ...
## $ Funding_for_the_MBA_Program : Factor w/ 6 levels "Family","Loan",..: 4 1 1 1 3 1 2 3 1 1 ...
## $ Work_Experience : Factor w/ 6 levels "1-2 year","2-3 year",..: 6 6 6 2 6 4 6 6 6 2 ...
## $ Career_options_after_MBA : Factor w/ 5 levels "Family Business",..: 3 4 3 3 3 3 3 3 3 3 ...
## $ Alternate_Career_Option_after_MBA_if_not_selected_through_Instit: Factor w/ 5 levels "Family Business",..: 3 4 3 3 3 3 3 3 3 2 ...
## $ perceivedscorecat : Factor w/ 3 levels "desired skills",..: 2 2 2 1 3 2 2 2 2 1 ...
# fix(mbaper)
dim(mbaper)
## [1] 273 19
summary(mbaper)
## Age_in_years_completed Percentage_in_10_Class Percentage_in_12_Class
## Min. :19.00 Min. :56.00 Min. :57.00
## 1st Qu.:21.00 1st Qu.:77.90 1st Qu.:73.60
## Median :22.00 Median :84.50 Median :82.00
## Mean :22.41 Mean :83.32 Mean :80.57
## 3rd Qu.:24.00 3rd Qu.:89.76 3rd Qu.:88.00
## Max. :28.00 Max. :97.20 Max. :97.17
##
## Percentage_in_Under_Graduate Gender STATE
## Min. :58.00 Female:120 south zone :140
## 1st Qu.:67.10 Male :153 North Zone : 55
## Median :72.83 East Zone : 39
## Mean :73.35 Central Zone : 20
## 3rd Qu.:78.60 west Zone : 9
## Max. :94.00 North East Zone: 4
## (Other) : 6
## Previous_Degree Fathers_qualification
## Arts : 4 Under Graduate :156
## Commerce :101 Post Graduation : 60
## Engineering:108 HSC : 20
## Journalism : 1 no formal Education : 12
## Management : 36 DIPLOMA : 10
## Science : 23 PhD or higher qualificati: 5
## (Other) : 10
## Mothers_qualification Fathers_occupation
## DIPLOMA : 4 Farming : 12
## HSC : 29 Not Alive : 4
## no formal Education : 15 others : 3
## PhD or higher qualificati: 4 Professional Job:101
## Post Graduation : 61 RETIRED : 9
## SSC : 21 Self employed :118
## Under Graduate :139 Technical Job : 26
## Mothers_occupation Marital_status Place_you_belong_to
## House wife :176 Married: 7 Rural : 24
## Professional Job: 74 Single :266 Semi Urban: 62
## Self employed : 16 Urban :187
## Technical Job : 7
##
##
##
## Total_Family_Income_per_annum Funding_for_the_MBA_Program
## 0-3 Lakh :50 Family :118
## 10-15 lakh :30 Loan : 49
## 15 lakh and above:24 Loan and family: 44
## 3-5 Lakh :56 Loan and self : 22
## 5-7 Lakh :56 Self : 35
## 7- 10 Lakh :57 Self and Family: 5
##
## Work_Experience Career_options_after_MBA
## 1-2 year : 45 Family Business : 2
## 2-3 year : 33 Higher Studies : 2
## 3-4 year : 6 Job :252
## 4-5 year : 2 Not yet decided : 4
## less than 1 year: 25 Self-employed/ entreprene: 13
## no experience :162
##
## Alternate_Career_Option_after_MBA_if_not_selected_through_Instit
## Family Business : 12
## Higher Studies : 30
## Job :135
## Not yet decided : 24
## Self-employed/ entreprene: 72
##
##
## perceivedscorecat
## desired skills : 93
## prefered skills:172
## required skills: 8
##
##
##
##
descr::descr(mbaper)
##
## Age_in_years_completed
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 19.00 21.00 22.00 22.41 24.00 28.00
##
## Percentage_in_10_Class
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 56.00 77.90 84.50 83.32 89.76 97.20
##
## Percentage_in_12_Class
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 57.00 73.60 82.00 80.57 88.00 97.17
##
## Percentage_in_Under_Graduate
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 58.00 67.10 72.83 73.35 78.60 94.00
##
## Gender
## Female Male
## 120 153
##
## STATE
## Central Zone East Zone GOA GUJARAT
## 20 39 1 2
## Nepal North East Zone North Zone North ZOne
## 1 4 55 2
## south zone west Zone
## 140 9
##
## Previous_Degree
## Arts Commerce Engineering Journalism Management Science
## 4 101 108 1 36 23
##
## Fathers_qualification
## CA/CS DIPLOMA
## 3 10
## HSC no formal Education
## 20 12
## Not Alive PhD or higher qualificati
## 3 5
## Post Graduation SSC
## 60 4
## Under Graduate
## 156
##
## Mothers_qualification
## DIPLOMA HSC
## 4 29
## no formal Education PhD or higher qualificati
## 15 4
## Post Graduation SSC
## 61 21
## Under Graduate
## 139
##
## Fathers_occupation
## Farming Not Alive others Professional Job
## 12 4 3 101
## RETIRED Self employed Technical Job
## 9 118 26
##
## Mothers_occupation
## House wife Professional Job Self employed Technical Job
## 176 74 16 7
##
## Marital_status
## Married Single
## 7 266
##
## Place_you_belong_to
## Rural Semi Urban Urban
## 24 62 187
##
## Total_Family_Income_per_annum
## 0-3 Lakh 10-15 lakh 15 lakh and above 3-5 Lakh
## 50 30 24 56
## 5-7 Lakh 7- 10 Lakh
## 56 57
##
## Funding_for_the_MBA_Program
## Family Loan Loan and family Loan and self
## 118 49 44 22
## Self Self and Family
## 35 5
##
## Work_Experience
## 1-2 year 2-3 year 3-4 year 4-5 year
## 45 33 6 2
## less than 1 year no experience
## 25 162
##
## Career_options_after_MBA
## Family Business Higher Studies
## 2 2
## Job Not yet decided
## 252 4
## Self-employed/ entreprene
## 13
##
## Alternate_Career_Option_after_MBA_if_not_selected_through_Instit
## Family Business Higher Studies
## 12 30
## Job Not yet decided
## 135 24
## Self-employed/ entreprene
## 72
##
## perceivedscorecat
## desired skills prefered skills required skills
## 93 172 8
library(graphics)
library(ggplot2)
#Import the file- MBAdata.csv and save as an R object mbaper
# import the file from the location-
mbaper<-read.csv("D:/1 Teaching Material/R/importfile/MBAdata.csv")
# study the data which is imported
str(mbaper)
## 'data.frame': 273 obs. of 19 variables:
## $ Age_in_years_completed : int 23 21 23 25 22 26 24 22 22 26 ...
## $ Percentage_in_10_Class : num 75 68 89.3 71.7 91.2 ...
## $ Percentage_in_12_Class : num 74 78 84.6 90 91.2 ...
## $ Percentage_in_Under_Graduate : num 67 65 66.4 73 70 ...
## $ Gender : Factor w/ 2 levels "Female","Male": 2 1 2 1 1 1 1 2 2 2 ...
## $ STATE : Factor w/ 10 levels "Central Zone",..: 6 6 6 6 1 1 1 1 1 1 ...
## $ Previous_Degree : Factor w/ 6 levels "Arts","Commerce",..: 2 2 3 2 2 3 3 3 3 3 ...
## $ Fathers_qualification : Factor w/ 9 levels "CA/CS","DIPLOMA",..: 2 9 9 9 9 5 7 7 9 9 ...
## $ Mothers_qualification : Factor w/ 7 levels "DIPLOMA","HSC",..: 1 6 2 7 5 5 2 7 7 7 ...
## $ Fathers_occupation : Factor w/ 7 levels "Farming","Not Alive",..: 4 6 5 7 4 2 4 4 4 7 ...
## $ Mothers_occupation : Factor w/ 4 levels "House wife","Professional Job",..: 2 1 1 1 2 1 1 2 1 1 ...
## $ Marital_status : Factor w/ 2 levels "Married","Single": 2 2 2 2 2 1 2 2 2 2 ...
## $ Place_you_belong_to : Factor w/ 3 levels "Rural","Semi Urban",..: 3 1 2 3 3 3 3 2 3 2 ...
## $ Total_Family_Income_per_annum : Factor w/ 6 levels "0-3 Lakh","10-15 lakh",..: 6 2 4 2 4 1 2 6 6 3 ...
## $ Funding_for_the_MBA_Program : Factor w/ 6 levels "Family","Loan",..: 4 1 1 1 3 1 2 3 1 1 ...
## $ Work_Experience : Factor w/ 6 levels "1-2 year","2-3 year",..: 6 6 6 2 6 4 6 6 6 2 ...
## $ Career_options_after_MBA : Factor w/ 5 levels "Family Business",..: 3 4 3 3 3 3 3 3 3 3 ...
## $ Alternate_Career_Option_after_MBA_if_not_selected_through_Instit: Factor w/ 5 levels "Family Business",..: 3 4 3 3 3 3 3 3 3 2 ...
## $ perceivedscorecat : Factor w/ 3 levels "desired skills",..: 2 2 2 1 3 2 2 2 2 1 ...
# fix(mbaper)
dim(mbaper)
## [1] 273 19
summary(mbaper)
## Age_in_years_completed Percentage_in_10_Class Percentage_in_12_Class
## Min. :19.00 Min. :56.00 Min. :57.00
## 1st Qu.:21.00 1st Qu.:77.90 1st Qu.:73.60
## Median :22.00 Median :84.50 Median :82.00
## Mean :22.41 Mean :83.32 Mean :80.57
## 3rd Qu.:24.00 3rd Qu.:89.76 3rd Qu.:88.00
## Max. :28.00 Max. :97.20 Max. :97.17
##
## Percentage_in_Under_Graduate Gender STATE
## Min. :58.00 Female:120 south zone :140
## 1st Qu.:67.10 Male :153 North Zone : 55
## Median :72.83 East Zone : 39
## Mean :73.35 Central Zone : 20
## 3rd Qu.:78.60 west Zone : 9
## Max. :94.00 North East Zone: 4
## (Other) : 6
## Previous_Degree Fathers_qualification
## Arts : 4 Under Graduate :156
## Commerce :101 Post Graduation : 60
## Engineering:108 HSC : 20
## Journalism : 1 no formal Education : 12
## Management : 36 DIPLOMA : 10
## Science : 23 PhD or higher qualificati: 5
## (Other) : 10
## Mothers_qualification Fathers_occupation
## DIPLOMA : 4 Farming : 12
## HSC : 29 Not Alive : 4
## no formal Education : 15 others : 3
## PhD or higher qualificati: 4 Professional Job:101
## Post Graduation : 61 RETIRED : 9
## SSC : 21 Self employed :118
## Under Graduate :139 Technical Job : 26
## Mothers_occupation Marital_status Place_you_belong_to
## House wife :176 Married: 7 Rural : 24
## Professional Job: 74 Single :266 Semi Urban: 62
## Self employed : 16 Urban :187
## Technical Job : 7
##
##
##
## Total_Family_Income_per_annum Funding_for_the_MBA_Program
## 0-3 Lakh :50 Family :118
## 10-15 lakh :30 Loan : 49
## 15 lakh and above:24 Loan and family: 44
## 3-5 Lakh :56 Loan and self : 22
## 5-7 Lakh :56 Self : 35
## 7- 10 Lakh :57 Self and Family: 5
##
## Work_Experience Career_options_after_MBA
## 1-2 year : 45 Family Business : 2
## 2-3 year : 33 Higher Studies : 2
## 3-4 year : 6 Job :252
## 4-5 year : 2 Not yet decided : 4
## less than 1 year: 25 Self-employed/ entreprene: 13
## no experience :162
##
## Alternate_Career_Option_after_MBA_if_not_selected_through_Instit
## Family Business : 12
## Higher Studies : 30
## Job :135
## Not yet decided : 24
## Self-employed/ entreprene: 72
##
##
## perceivedscorecat
## desired skills : 93
## prefered skills:172
## required skills: 8
##
##
##
##
descr::descr(mbaper)
##
## Age_in_years_completed
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 19.00 21.00 22.00 22.41 24.00 28.00
##
## Percentage_in_10_Class
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 56.00 77.90 84.50 83.32 89.76 97.20
##
## Percentage_in_12_Class
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 57.00 73.60 82.00 80.57 88.00 97.17
##
## Percentage_in_Under_Graduate
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 58.00 67.10 72.83 73.35 78.60 94.00
##
## Gender
## Female Male
## 120 153
##
## STATE
## Central Zone East Zone GOA GUJARAT
## 20 39 1 2
## Nepal North East Zone North Zone North ZOne
## 1 4 55 2
## south zone west Zone
## 140 9
##
## Previous_Degree
## Arts Commerce Engineering Journalism Management Science
## 4 101 108 1 36 23
##
## Fathers_qualification
## CA/CS DIPLOMA
## 3 10
## HSC no formal Education
## 20 12
## Not Alive PhD or higher qualificati
## 3 5
## Post Graduation SSC
## 60 4
## Under Graduate
## 156
##
## Mothers_qualification
## DIPLOMA HSC
## 4 29
## no formal Education PhD or higher qualificati
## 15 4
## Post Graduation SSC
## 61 21
## Under Graduate
## 139
##
## Fathers_occupation
## Farming Not Alive others Professional Job
## 12 4 3 101
## RETIRED Self employed Technical Job
## 9 118 26
##
## Mothers_occupation
## House wife Professional Job Self employed Technical Job
## 176 74 16 7
##
## Marital_status
## Married Single
## 7 266
##
## Place_you_belong_to
## Rural Semi Urban Urban
## 24 62 187
##
## Total_Family_Income_per_annum
## 0-3 Lakh 10-15 lakh 15 lakh and above 3-5 Lakh
## 50 30 24 56
## 5-7 Lakh 7- 10 Lakh
## 56 57
##
## Funding_for_the_MBA_Program
## Family Loan Loan and family Loan and self
## 118 49 44 22
## Self Self and Family
## 35 5
##
## Work_Experience
## 1-2 year 2-3 year 3-4 year 4-5 year
## 45 33 6 2
## less than 1 year no experience
## 25 162
##
## Career_options_after_MBA
## Family Business Higher Studies
## 2 2
## Job Not yet decided
## 252 4
## Self-employed/ entreprene
## 13
##
## Alternate_Career_Option_after_MBA_if_not_selected_through_Instit
## Family Business Higher Studies
## 12 30
## Job Not yet decided
## 135 24
## Self-employed/ entreprene
## 72
##
## perceivedscorecat
## desired skills prefered skills required skills
## 93 172 8
for missing observations we will use an.omit so that all the observations with missing values will be omitted. If there are missing observation there will be a problem in using the commands
mbaper<-na.omit(mbaper)
# check the number of omitted observations
dim(mbaper)
## [1] 273 19
#convert all the categorical variables into factor
# first remove the missing values then convert to factor, as na may be converted to factor/ categories
mbaper$Gender<-as.factor(mbaper$Gender)
mbaper$STATE<-as.factor(mbaper$STATE)
mbaper$Previous_Degree<-as.factor(mbaper$Previous_Degree)
mbaper$perceivedscorecat<-as.factor(mbaper$perceivedscorecat)
mbaper$Marital_status<-as.factor(mbaper$Marital_status)
mbaper$Place_you_belong_to<-as.factor(mbaper$Place_you_belong_to)
#Study the data using graphs and charts
code for ggplot
args(ggplot)
ggplot(df, aes(x, y, ))
#single scale variable-
# 10th percentage of student
library(ggplot2)
ggplot(mbaper, aes(mbaper$Percentage_in_10_Class))+geom_dotplot()
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
ggplot(mbaper, aes(mbaper$Percentage_in_10_Class))+geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
ggplot(mbaper, aes(mbaper$Percentage_in_10_Class))+geom_freqpoly()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
ggplot(mbaper, aes(mbaper$Percentage_in_10_Class))+geom_density()
# density plot is an alternative of Histogram
mbaper<-na.omit(mbaper)
# check the number of omitted observations
dim(mbaper)
## [1] 273 19
#convert all the categorical variables into factor
# first remove the missing values then convert to factor, as na may be converted to factor/ categories
mbaper$Gender<-as.factor(mbaper$Gender)
mbaper$STATE<-as.factor(mbaper$STATE)
mbaper$Previous_Degree<-as.factor(mbaper$Previous_Degree)
mbaper$perceivedscorecat<-as.factor(mbaper$perceivedscorecat)
mbaper$Marital_status<-as.factor(mbaper$Marital_status)
mbaper$Place_you_belong_to<-as.factor(mbaper$Place_you_belong_to)
#Study the data using graphs and charts
code for ggplot
args(ggplot)
ggplot(df, aes(x, y, ))
#single scale variable-
# 10th percentage of student
library(ggplot2)
ggplot(mbaper, aes(mbaper$Percentage_in_10_Class))+geom_dotplot()
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
ggplot(mbaper, aes(mbaper$Percentage_in_10_Class))+geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
ggplot(mbaper, aes(mbaper$Percentage_in_10_Class))+geom_freqpoly()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
ggplot(mbaper, aes(mbaper$Percentage_in_10_Class))+geom_density()
# density plot is an alternative of Histogram
12th percentage of student
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class))+geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class))+geom_freqpoly()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class))+geom_density()
# density plot is an alternative of Histogram
#two scale variables
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class, mbaper$Percentage_in_10_Class))+ geom_point()
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class, mbaper$Percentage_in_10_Class))+ geom_jitter()
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class, mbaper$Percentage_in_10_Class))+ geom_line()
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class, mbaper$Percentage_in_10_Class))+geom_smooth()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class, mbaper$Percentage_in_10_Class))+ geom_bin2d()
single categorical data
ggplot(mbaper, aes(mbaper$Gender))+geom_bar()
ggplot(mbaper, aes(mbaper$Previous_Degree))+ geom_bar()
ggplot(mbaper, aes(mbaper$STATE))+ geom_bar()
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class))+geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class))+geom_freqpoly()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class))+geom_density()
# density plot is an alternative of Histogram
#two scale variables
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class, mbaper$Percentage_in_10_Class))+ geom_point()
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class, mbaper$Percentage_in_10_Class))+ geom_jitter()
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class, mbaper$Percentage_in_10_Class))+ geom_line()
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class, mbaper$Percentage_in_10_Class))+geom_smooth()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
ggplot(mbaper, aes(mbaper$Percentage_in_12_Class, mbaper$Percentage_in_10_Class))+ geom_bin2d()
single categorical data
ggplot(mbaper, aes(mbaper$Gender))+geom_bar()
ggplot(mbaper, aes(mbaper$Previous_Degree))+ geom_bar()
ggplot(mbaper, aes(mbaper$STATE))+ geom_bar()
two categorical variable
adding one more categorical variable- use fill
ggplot(mbaper, aes(mbaper$Gender, fill=mbaper$Marital_status))+ geom_bar()
ggplot(mbaper, aes(mbaper$Gender, fill=mbaper$Place_you_belong_to))+ geom_bar()
in geom_bar use position for different types of bar graph
ggplot(mbaper, aes(mbaper$Gender, fill= mbaper$Place_you_belong_to))+ geom_bar(position = "dodge")
ggplot(mbaper, aes(mbaper$Gender, fill= mbaper$Place_you_belong_to))+ geom_bar(position = "stack")
ggplot(mbaper, aes(mbaper$Gender, fill= mbaper$Place_you_belong_to))+ geom_bar(position = "fill")
ggplot(mbaper, aes(mbaper$Gender, fill=mbaper$Marital_status))+ geom_bar()
ggplot(mbaper, aes(mbaper$Gender, fill=mbaper$Place_you_belong_to))+ geom_bar()
in geom_bar use position for different types of bar graph
ggplot(mbaper, aes(mbaper$Gender, fill= mbaper$Place_you_belong_to))+ geom_bar(position = "dodge")
ggplot(mbaper, aes(mbaper$Gender, fill= mbaper$Place_you_belong_to))+ geom_bar(position = "stack")
ggplot(mbaper, aes(mbaper$Gender, fill= mbaper$Place_you_belong_to))+ geom_bar(position = "fill")
Instead of Bar graphs we can use mosaic
ggplot(mbaper, aes(mbaper$Gender, mbaper$Previous_Degree))+ geom_bin2d()
use facet to add layer
ggplot(mbaper, aes(mbaper$Gender, fill=mbaper$Place_you_belong_to))+ geom_bar()+facet_grid(~mbaper$Previous_Degree)
ggplot(mbaper, aes(mbaper$Gender, fill=mbaper$Place_you_belong_to))+ geom_bar()+facet_wrap(~mbaper$Previous_Degree)
can add multiple layears
ggplot(mbaper, aes(mbaper$Gender, fill=mbaper$Place_you_belong_to))+ geom_bar()+facet_grid(~mbaper$Previous_Degree+mbaper$Marital_status)
Note: In the Code we dont have to write the name of the data file again and again
Example:-
ggplot(mbaper, aes(Gender, fill=Place_you_belong_to))+ geom_bar()+facet_grid(~Previous_Degree+Marital_status)
ggplot(mbaper, aes(mbaper$Gender, mbaper$Previous_Degree))+ geom_bin2d()
use facet to add layer
ggplot(mbaper, aes(mbaper$Gender, fill=mbaper$Place_you_belong_to))+ geom_bar()+facet_grid(~mbaper$Previous_Degree)
ggplot(mbaper, aes(mbaper$Gender, fill=mbaper$Place_you_belong_to))+ geom_bar()+facet_wrap(~mbaper$Previous_Degree)
can add multiple layears
ggplot(mbaper, aes(mbaper$Gender, fill=mbaper$Place_you_belong_to))+ geom_bar()+facet_grid(~mbaper$Previous_Degree+mbaper$Marital_status)
Note: In the Code we dont have to write the name of the data file again and again
Example:-
ggplot(mbaper, aes(Gender, fill=Place_you_belong_to))+ geom_bar()+facet_grid(~Previous_Degree+Marital_status)