Tuesday, June 19, 2018

Basics of R session 7- Data Visualization Mosaic Plot

Use library vcd
mosaic will be used for categorical variables
#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")

library(vcd)
## Loading required package: grid
#here the data set used is mbaper, and the variable used is Marital_status

mosaic(~mbaper$Marital_status)
mosaic(~Marital_status, data= mbaper)
# here the output will be different in terms of labeling- the block name as the labels of the variable Marital_status, and the title will be the name of the data
Adding variables
mosaic(~mbaper$Gender+mbaper$Marital_status+mbaper$Place_you_belong_to)
mosaic(~Gender+Marital_status+Place_you_belong_to, data = mbaper)

cross tab mosaic

mosaic(mbaper$Gender~mbaper$Marital_status)

adding variables

mosaic(mbaper$Gender~mbaper$Marital_status+mbaper$perceivedscorecat)
mosaic(mbaper$Gender~mbaper$Marital_status+mbaper$perceivedscorecat+mbaper$Place_you_belong_to)
mosaic(mbaper$Gender~mbaper$Marital_status)
rotating the label for better visibility
mosaic(~mbaper$Gender+mbaper$Marital_status, labeling= labeling_border(rot_labels = c(45,45,45,45)))
if there are null blocks or no observation in the combination cell, nothing will be displayed if zero_size=0
mosaic(~mbaper$Gender+mbaper$STATE, zero_size= 0)
for colouring the mosaic, wth specific colour
mosaic(~mbaper$Marital_status, gp= gpar(fill=c("red", "green")))
different types of shading based on residual
mosaic(~mbaper$Gender+mbaper$Marital_status, gp = shading_hcl)
mosaic(~mbaper$Gender+mbaper$Marital_status, gp = shading_hsv)
mosaic(~mbaper$Gender+mbaper$Marital_status, gp = shading_max)
mosaic(~mbaper$Gender+mbaper$Marital_status, gp = shading_Friendly)
mosaic(~mbaper$Gender+mbaper$Marital_status, gp = shading_Friendly2)
mosaic(~mbaper$Gender+mbaper$Marital_status, gp = shading_sieve)
mosaic(~mbaper$Gender+mbaper$Marital_status, gp = shading_binary)

No comments:

Post a Comment