#Begin####
pacman::p_load(openxlsx,pacman,tidyverse)
setwd("D:/r")
#load Data
npl <- read.xlsx("npl.xlsx")
View(npl)
names(npl)<-str_to_lower(names(npl))
str(npl)
#some changes
npl$gender<-as.factor(npl$gender)
npl$year<-as.factor(npl$year)
#Basic#######################################################################################
# geom_bar-> bar graph
# aes->aesthetics, what should be on the x axis
# fill->what to put in the same plot/ What will be the separating parametre
# total, fill = year-> total separated year wise
# labs-> label,(title,x,y)
# scale_fill_manual->fill colors
# theme->set position of title
# facet_wrap(prop~.)->data separated prop wise and place next to each other
#
# geom_boxplot(notch = T)-> box plot
#
# geom density->density curve
#
# position = position_dodge()-> puts multiplt bars next to each other
################################################################################
#Most basic plot without colors####
png("result.png")
npl %>% ggplot(aes(gender))+
geom_bar()
dev.off()
file.show("result.png")
#plots with auto color====
png("result1.png")
npl %>% ggplot(aes(gender, fill = gender))+#aes - aesthetic
geom_bar()
dev.off()
file.show("result1.png")
#plots with color and labels####
png("result2.png")
npl %>% ggplot(aes(gender, fill = gender))+#aes - aesthetic
geom_bar()+
labs(title = "Total Partisopant genderWise", x = "gender", y = "No. of participants")
dev.off()
file.show("result2.png")
#Specify the colors using rainbow####
png("result3.png")
npl %>% ggplot(aes(gender, fill = gender))+#aes - aesthetic
geom_bar()+
labs(title = "Total Partisopant genderWise",
x = "gender", y = "No. of participants")+
scale_fill_manual(values = rainbow(2), name = "Legend", breaks = c("0","1"),
labels = c("Male", "Female"))+
theme(plot.title=element_text(hjust=0.5))
dev.off()
file.show("result3.png")
#legend position, tital position
palette()#current palette
palette.pals()#
#Set color of your choice ####
png("result4.png")
npl %>% ggplot(aes(gender, fill = gender))+#aes - aesthetic
geom_bar()+
labs(title = "Total Partisopant genderWise",
x = "gender", y = "No. of participants")+
scale_fill_manual(values = c("blue", "pink"), name = "Legend", breaks = c("0","1"),
labels = c("Male", "Female"))+
theme(plot.title=element_text(hjust=0.5))
dev.off()
file.show("result4.png")
#gender with year facet_wrap####
png("result5.png")
npl %>% ggplot(aes(gender, fill = gender))+#aes - aesthetic
geom_bar()+
facet_wrap(year~.)+
labs(title = "Total Partisopant genderWise",
x = "gender", y = "No. of participants")+
scale_fill_manual(values = c("blue", "pink"), name = "Legend", breaks = c("0","1"),
labels = c("Male", "Female"))+
theme(plot.title=element_text(hjust=0.5))
dev.off()
file.show("result5.png")
#box plot totalScore and gender####
png("result6.png")
npl %>% ggplot(aes(total, fill = gender))+#aes - aesthetic
geom_boxplot(notch = T)+
labs(title = "Total Partisopant genderWise",
x = "gender", y = "No. of participants")+
scale_fill_manual(values = c("blue", "pink"), name = "Legend", breaks = c("0","1"),
labels = c("Male", "Female"))+
theme(plot.title=element_text(hjust=0.5))
dev.off()
file.show("result6.png")
#quartile
#box plot with total score and year####
png("result7.png")
npl %>% ggplot(aes(total, fill = year))+#aes - aesthetic
geom_boxplot(notch = T)+
labs(title = "Total Partisopant YearWise",
x="total", y="year")+
theme(plot.title=element_text(hjust=0.5))
dev.off()
file.show("result7.png")
#geom density####
#Total
png("result8.png")
npl %>% ggplot(aes(total, fill = gender))+#aes - aesthetic
geom_density(alpha=0.5)+
labs(title = "Total Partisopant genderWise",
x = "gender", y = "No. of participants")+
scale_fill_manual(values = c("blue", "pink"), name = "Legend", breaks = c("0","1"),
labels = c("Male", "Female"))+
theme(plot.title=element_text(hjust=0.5))
dev.off()
file.show("result8.png")
#Theory
png("result9.png")
npl %>% ggplot(aes(theory, fill = gender))+#aes - aesthetic
geom_density(alpha=0.5)+
labs(title = "Total Partisopant genderWise",
x = "gender", y = "No. of participants")+
scale_fill_manual(values = c("blue", "pink"), name = "Legend", breaks = c("0","1"),
labels = c("Male", "Female"))+
theme(plot.title=element_text(hjust=0.5))
dev.off()
file.show("result9.png")
#lab
png("result10.png")
npl %>% ggplot(aes(lab, fill = gender))+#aes - aesthetic
geom_density(alpha=0.5)+
labs(title = "Total Partisopant genderWise",
x = "gender", y = "No. of participants")+
scale_fill_manual(values = c("blue", "pink"), name = "Legend", breaks = c("0","1"),
labels = c("Male", "Female"))+
theme(plot.title=element_text(hjust=0.5))
dev.off()
file.show("result10.png")
#geom density with facet_wrap####
png("result11.png")
npl %>% ggplot(aes(total, fill = gender))+#aes - aesthetic
geom_density(alpha=0.5)+
facet_wrap(year~.)+
labs(title = "Total Partisopant genderWise",
x = "gender", y = "No. of participants")+
scale_fill_manual(values = c("blue", "pink"), name = "Legend", breaks = c("0","1"),
labels = c("Male", "Female"))+
theme(plot.title=element_text(hjust=0.5))
dev.off()
file.show("result11.png")
# ####
png("result12.png")
npl %>% ggplot(aes(year, fill = gender))+#aes - aesthetic
geom_bar(position = position_dodge())+
#facet_wrap(year~.)+
labs(title = "Total Partisopant genderWise",
x = "gender", y = "No. of participants")+
scale_fill_manual(values = c("blue", "pink"), name = "Legend", breaks = c("0","1"),
labels = c("Male", "Female"))+
theme(plot.title=element_text(hjust=0.5))
dev.off()
file.show("result12.png")
# geom_jitter()