This example RMD file shows student numbers in the School of Computer Science, University of Manchester.

Loading data

library(xlsx)
## Loading required package: rJava
## Loading required package: xlsxjars
library(ggplot2)
library(reshape2)
library(scales)
library(knitr)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(xtable)

x <- read.xlsx("data.xlsx",sheetIndex=1)
x$count<-as.numeric(as.character(x$count))
df_all_sn<-x[c("school","sex","count","time_type", "student_type", "year")]
nr<-nrow(df_all_sn)

The dataset has 192 rows. And it is mine. To see the interactive Shiny Version of this document, see here.

Data pre-processing

d<-df_all_sn[df_all_sn$school=="School of Computer Science"&!(df_all_sn$year %in% c("2013/2014")),]#d1[d1$school=="School of Computer Science",][c("count","sex","student_type","year","pc_sex","time_type")]

#Counts of men and women broken down by course type
df_sn<-aggregate(d$count,by=list(d$year,d$sex,d$student_type),FUN=function(x) {sum(x,na.rm = TRUE)})
names(df_sn)<-c("year","sex","student_type","count")
df_sn<-reshape(df_sn,direction = "wide",timevar = "sex",idvar = c("year","student_type"))
df_sn$count.total<-df_sn$count.Female+df_sn$count.Male
df_sn<-melt(df_sn,id.vars = c("year","student_type","count.total"))
df_sn$variable<-gsub(pattern = "count.",replacement = "",x = df_sn$variable)
df_sn$value.pc<-pc(df_sn$value,df_sn$count.total)
#df_sn$value.pcconn = pcrescaled(df_sn$value.pc,c(0,50))+20

Analysis

ggplot(df_sn[df_sn$variable=="Female",],aes_string(x="year",y="value.pc",group="student_type")) + geom_line() + xlab("Year") + ylab("Percentage of female students") + facet_wrap("student_type", scales = "fixed",ncol = 3) + ggtitle("Female students by program") + geom_label(stat="identity",aes_string(y="value.pc",label="paste(value,\"\n(\",value.pc,\"%)\",sep=\"\")"),size=3)  + ylim(14 ,36)

ggsave("sn_pc_all.jpg",width = 9,height = 3)

kable(df_all_sn[df_all_sn$school=="School of Computer Science"&!(df_all_sn$year %in% c("2013/2014")),], options = list(lengthMenu = c(5, 10, 50,100), pageLength = 5))
school sex count time_type student_type year
3 School of Computer Science Female 106 Full Time Undergraduate 2015/2016
4 School of Computer Science Male 594 Full Time Undergraduate 2015/2016
11 School of Computer Science Female 1 Part Time Undergraduate 2015/2016
12 School of Computer Science Male 2 Part Time Undergraduate 2015/2016
19 School of Computer Science Female 54 Full Time Postgraduate Taught 2015/2016
20 School of Computer Science Male 100 Full Time Postgraduate Taught 2015/2016
27 School of Computer Science Female 16 Part Time Postgraduate Taught 2015/2016
28 School of Computer Science Male 40 Part Time Postgraduate Taught 2015/2016
35 School of Computer Science Female 35 Full Time Postgraduate Research 2015/2016
36 School of Computer Science Male 108 Full Time Postgraduate Research 2015/2016
43 School of Computer Science Female 2 Part Time Postgraduate Research 2015/2016
44 School of Computer Science Male 5 Part Time Postgraduate Research 2015/2016
51 School of Computer Science Female 106 Full Time Undergraduate 2014/2015
52 School of Computer Science Male 590 Full Time Undergraduate 2014/2015
59 School of Computer Science Female 0 Part Time Undergraduate 2014/2015
60 School of Computer Science Male 0 Part Time Undergraduate 2014/2015
67 School of Computer Science Female 60 Full Time Postgraduate Taught 2014/2015
68 School of Computer Science Male 110 Full Time Postgraduate Taught 2014/2015
75 School of Computer Science Female 29 Part Time Postgraduate Taught 2014/2015
76 School of Computer Science Male 57 Part Time Postgraduate Taught 2014/2015
83 School of Computer Science Female 24 Full Time Postgraduate Research 2014/2015
84 School of Computer Science Male 122 Full Time Postgraduate Research 2014/2015
91 School of Computer Science Female 3 Part Time Postgraduate Research 2014/2015
92 School of Computer Science Male 5 Part Time Postgraduate Research 2014/2015
147 School of Computer Science Female 146 Full Time Undergraduate 2016/2017
148 School of Computer Science Male 613 Full Time Undergraduate 2016/2017
155 School of Computer Science Female 0 Part Time Undergraduate 2016/2017
156 School of Computer Science Male 2 Part Time Undergraduate 2016/2017
163 School of Computer Science Female 56 Full Time Postgraduate Taught 2016/2017
164 School of Computer Science Male 89 Full Time Postgraduate Taught 2016/2017
171 School of Computer Science Female 12 Part Time Postgraduate Taught 2016/2017
172 School of Computer Science Male 38 Part Time Postgraduate Taught 2016/2017
179 School of Computer Science Female 40 Full Time Postgraduate Research 2016/2017
180 School of Computer Science Male 86 Full Time Postgraduate Research 2016/2017
187 School of Computer Science Female 1 Part Time Postgraduate Research 2016/2017
188 School of Computer Science Male 6 Part Time Postgraduate Research 2016/2017