Psyphdblog.files.wordpress.com



library(pacman) # install if not already installedp_load(readxl, tidyverse)#Working Directory#Chec your working directorygetwd()#Change your working directorysetwd("C:\\Users\\ALICI\\Dropbox\\Work\\Blog\\R scripts\\Cumulative Distribution Graph")#setwd("C:\\Users\\name\\of\\directory")#Import Excel sheetdf <- read_excel("dataset01.xlsx")str(df)#Summrise the datasetsummariseddata<-df %>% group_by(Percentage) %>% filter(Percentage != -999) %>% summarise(n= n()) %>% mutate(prop=n/sum(n), percent = prop*100, cumpercent=cumsum(percent), CI_L=(prop-1.959964*sqrt(prop*(1-prop)/sum(n)))*100, CI_U=(prop+1.959964*sqrt(prop*(1-prop)/sum(n)))*100)summariseddata<-round(summariseddata,2)#Step Oneplot<- ggplot(summariseddata, aes(x=Percentage, y=percent, fill=Percentage)) + geom_bar(stat="identity", fill = "#b5b3b3") + geom_errorbar(aes(ymin=CI_L, ymax = CI_U), width=0.8)plot#Step Twoplot<- ggplot(summariseddata, aes(x=Percentage, y=percent, fill=Percentage)) + geom_bar(stat="identity",fill = "#b5b3b3") + geom_errorbar(aes(ymin=CI_L, ymax = CI_U), width=0.8)+ labs(y = "Per cent of responses", x = "Per cent of respondents who expressed satisfaction in their position")plot + expand_limits(y = c(0, 100))+ scale_x_continuous(breaks=unique(summariseddata$Percentage),labels = summariseddata$Percentage)+ scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 10))#Step Threeplot<- ggplot(summariseddata, aes(x=Percentage, y=percent, fill=Percentage)) + geom_bar(stat="identity",fill = "#b5b3b3") + geom_text(aes(label=paste(round(percent,2),"%",sep="")), position=position_dodge(width=0.9), vjust=-.80)+ labs(y = "Per cent of responses", x = "Per cent of respondents who expressed satisfaction in their position")plot + expand_limits(y = c(0, 100))+ scale_x_continuous(breaks=unique(summariseddata$Percentage),labels = summariseddata$Percentage)+ scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 10))#Step Four-aplot<- ggplot(summariseddata, aes(x=Percentage, y=percent, fill=Percentage)) + geom_line(aes(y=cumpercent), size=0.8,linetype="dashed",color = "#726f6f")+ geom_bar(stat="identity",fill = "#b5b3b3") + geom_text(aes(label=paste(round(percent,2),"%",sep="")), position=position_dodge(width=0.9), vjust=-.80)+ labs(y = "Per cent of responses", x = "Per cent of respondents who expressed satisfaction in their position")plot + expand_limits(y = c(0, 100))+ scale_x_continuous(breaks=unique(summariseddata$Percentage),labels = summariseddata$Percentage)+ scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 10))#Step Four-bplot<- ggplot(summariseddata, aes(x=Percentage, y=percent, fill=Percentage)) + geom_line(aes(y=cumpercent), size=0.8,linetype="dashed",color = "#726f6f")+ geom_point(aes(y=cumpercent), shape=1, size = 5)+ geom_text(aes(label=paste(round(cumpercent,2),"%",sep=""),x=Percentage, y =cumpercent), position=position_dodge(width=0.9), vjust=-.80, hjust = .7)+ geom_bar(stat="identity",fill = "#b5b3b3") + geom_text(aes(label=paste(round(percent,2),"%",sep="")), position=position_dodge(width=0.9), vjust=-.80)+ labs(y = "Per cent of responses", x = "Per cent of respondents who expressed satisfaction in their position")plot + guides(fill=FALSE) + expand_limits(y = c(0, 100))+ scale_x_continuous(breaks=unique(summariseddata$Percentage),labels = summariseddata$Percentage)+ scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 10))#Step Four-cplot<- ggplot(summariseddata, aes(x=Percentage, y=percent, fill=Percentage)) + geom_line(aes(y=cumpercent), size=0.8,linetype="dashed",color = "#726f6f")+ geom_point(aes(y=cumpercent), shape=1, size = 5)+ geom_text(aes(label=ifelse(cumpercent>10,paste(round(cumpercent,2),"%",sep=""),""), x=Percentage, y =cumpercent), position=position_dodge(width=0.9), vjust=-.80, hjust = .7)+ geom_bar(stat="identity",fill = "#b5b3b3") + geom_text(aes(label=paste(round(percent,2),"%",sep="")), position=position_dodge(width=0.9), vjust=-.80)+ labs(y = "Per cent of responses", x = "Per cent of respondents who expressed satisfaction in their position")plot + guides(fill=FALSE) + expand_limits(y = c(0, 100))+ scale_x_continuous(breaks=unique(summariseddata$Percentage),labels = summariseddata$Percentage)+ scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 10))#Step 5plot<- ggplot(summariseddata, aes(x=Percentage, y=percent, fill=Percentage)) + geom_line(aes(y=cumpercent), size=0.8,linetype="dashed",color = "#726f6f")+ geom_point(aes(y=cumpercent), shape=1, size = 5)+ geom_text(aes(label=ifelse(cumpercent>10,paste(round(cumpercent,2),"%",sep=""),""), x=Percentage, y =cumpercent), position=position_dodge(width=0.9), vjust=-.80, hjust = .7)+ geom_bar(stat="identity",fill = "#b5b3b3") + geom_text(aes(label=paste(round(percent,2),"%",sep="")), position=position_dodge(width=0.9), vjust=-.80)+ labs(y = "Per cent of responses", x = "Per cent of respondents who expressed satisfaction in their position")plot + guides(fill=FALSE) + expand_limits(y = c(0, 100))+ scale_x_continuous(breaks=unique(summariseddata$Percentage),labels = summariseddata$Percentage)+ scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 10))+ geom_vline(xintercept=45,linetype="longdash", color = "blue",size=0.8)+ geom_vline(xintercept=65,linetype="longdash", color = "red",size=0.8) #Step 5-blinehere40<-summariseddata$cumpercent[summariseddata$Percentage==40] linehere40<-round(linehere40,2)From40<-100-linehere40From40label<-paste(From40,"%", sep="")linehere60<-summariseddata$cumpercent[summariseddata$Percentage==60] linehere60<-round(linehere60,2)From60<-100-linehere60From60label<-paste(From60,"%", sep="")plot<- ggplot(summariseddata, aes(x=Percentage, y=percent, fill=Percentage)) + geom_line(aes(y=cumpercent), size=0.8,linetype="dashed",color = "#726f6f")+ geom_point(aes(y=cumpercent), shape=1, size = 5)+ geom_text(aes(label=ifelse(cumpercent>10,paste(round(cumpercent,2),"%",sep=""),""), x=Percentage, y =cumpercent), position=position_dodge(width=0.9), vjust=-.80, hjust = .7)+ geom_bar(stat="identity",fill = "#b5b3b3") + geom_text(aes(label=paste(round(percent,2),"%",sep="")), position=position_dodge(width=0.9), vjust=-.80)+ annotate("text",label = paste(From40label,"of \n respondents who answered \n 50% or more"), x = 55,y=15,vjust = -1,size=4,colour="blue") + annotate("text", label = paste(From60label,"of \n respondents who answered \n 70% or more"), x = 85,y=15,vjust = -1,size=4,colour ="red") + labs(y = "Per cent of responses", x = "Per cent of respondents who expressed satisfaction in their position")plot + guides(fill=FALSE) + expand_limits(y = c(0, 100))+ scale_x_continuous(breaks=unique(summariseddata$Percentage),labels = summariseddata$Percentage)+ scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 10))+ geom_vline(xintercept=45,linetype="longdash", color = "blue",size=0.8)+ geom_vline(xintercept=65,linetype="longdash", color = "red",size=0.8)#Step 5-cplot<- ggplot(summariseddata, aes(x=Percentage, y=percent, fill=Percentage)) + annotate("rect", xmin = 45, xmax = 65, ymin = 0, ymax = Inf, alpha = 0.2, fill ="blue")+ annotate("rect", xmin = 65, xmax = Inf, ymin = 0, ymax = Inf, alpha = .2, fill ="red")+ geom_line(aes(y=cumpercent), size=0.8,linetype="dashed",color = "#726f6f")+ geom_point(aes(y=cumpercent), shape=1, size = 5)+ geom_text(aes(label=ifelse(cumpercent>10,paste(round(cumpercent,2),"%",sep=""),""), x=Percentage, y =cumpercent), position=position_dodge(width=0.9), vjust=-.80, hjust = .7)+ geom_bar(stat="identity",fill = "#b5b3b3") + geom_text(aes(label=paste(round(percent,2),"%",sep="")), position=position_dodge(width=0.9), vjust=-.80)+ annotate("text",label = paste(From40label,"of \n respondents who answered \n 50% or more"), x = 55,y=15,vjust = -1,size=4,colour="blue") + annotate("text", label = paste(From60label,"of \n respondents who answered \n 70% or more"), x = 85,y=15,vjust = -1,size=4,colour ="red") + labs(y = "Per cent of responses", x = "Per cent of respondents who expressed satisfaction in their position")plot + guides(fill=FALSE) + expand_limits(y = c(0, 100))+ scale_x_continuous(breaks=unique(summariseddata$Percentage),labels = summariseddata$Percentage)+ scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 10))+ geom_vline(xintercept=45,linetype="longdash", color = "blue",size=0.8)+ geom_vline(xintercept=65,linetype="longdash", color = "red",size=0.8)#Step 5-dplot<- ggplot(summariseddata, aes(x=Percentage, y=percent, fill=Percentage)) + annotate("rect", xmin = 45, xmax = 65, ymin = 0, ymax = Inf, alpha = 0.2, fill ="blue")+ annotate("rect", xmin = 65, xmax = Inf, ymin = 0, ymax = Inf, alpha = .2, fill ="red")+ geom_line(aes(y=cumpercent), size=0.8,linetype="dashed",color = "#726f6f")+ geom_point(aes(y=cumpercent), shape=1, size = 5)+ geom_text(aes(label=ifelse(cumpercent>10,paste(round(cumpercent,2),"%",sep=""),""), x=Percentage, y =cumpercent), position=position_dodge(width=0.9), vjust=-.80, hjust = .7)+ geom_bar(stat="identity",fill = "#b5b3b3") + geom_text(aes(label=paste(round(percent,2),"%",sep="")), position=position_dodge(width=0.9), vjust=-.80)+ annotate("text",label = paste(From40label,"of \n respondents who answered \n 50% or more"), x = 55,y=15,vjust = -1,size=4,colour="blue") + annotate("text", label = paste(From60label,"of \n respondents who answered \n 70% or more"), x = 85,y=15,vjust = -1,size=4,colour ="red") + labs(y = "Per cent of responses", x = "Workplace Satisfaction (0-100%)", title="Per cent of respondents who expressed satisfaction in their workplace")plot + guides(fill=FALSE) + expand_limits(y = c(0, 100))+ scale_x_continuous(breaks=unique(summariseddata$Percentage),labels = summariseddata$Percentage)+ scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, by = 10))+ geom_vline(xintercept=45,linetype="longdash", color = "blue",size=0.8)+ geom_vline(xintercept=65,linetype="longdash", color = "red",size=0.8) ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download