View source: R/fnScoreHist_MR.R
1 | fnScoreHist(x,lo=0,hi=100,gradeScheme="",gradeBounds=c(),main="",ylab="Frequency (N students)",plotBox=TRUE,pcScore=TRUE)
|
x |
A vector of assessment scores (usually percentages but may exceed 100 or be negative). |
lo |
Minimum value for plotting the x axis, best given as an appropriate multiple of 10 because the axis labels are spaced in tens. If min(x)<lo then lo is adjusted downwards (in multiples of 10) |
hi |
Maximum value for plotting the x axis, If max(x)>hi then hi is adjusted upwards (in multiples of 10) |
gradeScheme |
A character string giving the first letter of the grades, ordered from lowest to highest. e.g. "UBSE" or "FP". Letters other than U, B, S, E, F or P will be displayed but not shaded. If gradeScheme is not specified then the background will be unshaded |
gradeBounds |
A numeric vector of grade thresholds. e.g. c(40,50,60). NOTE: length(gradeBounds) must equal nchar(gradeScheme) - 1, otherwise the background will be unshaded |
main |
Title for the plot, if required. |
ylab |
Label for the y axis. |
plotBox |
If TRUE (the default) adds a boxplot with mean point above the histogram. |
pcScore |
If TRUE (the default) changes the x axis label from "Score" to "Score ( |
A ggplot object which can be saved or customised as needed.
fnScoreHist creates a histogram of scores. Optional arguments draw a boxplot above the histogram and shade the plot background according to supplied grade boundaries.
The output from fnScoreHist is a ggplot object which can then be saved or customised as needed.
See Examples for more details.
This function uses ggplot
for the underlying graphics.
library("ggplot2")
library("psychometricsPSMD")
Basic Usage (examples employ randomly generated data so the resulting plots are variable)
fnScoreHist(x=rnorm(86,30,10),lo=-10,hi=80,gradeScheme="UBSE",gradeBounds=c(20,25,45))
Ability to accommodate NA values and to adjust lo and hi (set to 0 and 80 in this example) to fit data
fnScoreHist(x=c(-1,2,rnorm(86,30,10),65,93,100,NA),lo=0,hi=80,gradeScheme="USE",gradeBounds=c(18.25,45.62))
If length(gradeBounds) not equal to nchar(gradeScheme) - 1 then no background shading is carried out
fnScoreHist(x=rnorm(86,30,10),gradeScheme="FP",gradeBounds=c(18.25,25.62))
Scores need not be percentages and the boxplot can be removed
fnScoreHist(x=rnorm(86,150,20),lo=100,hi=200,gradeScheme="FP",gradeBounds=c(135),plotBox=FALSE,pcScore=FALSE)
Grade boundaries falling outside the lo-hi interval will cause the shading and grade labelling to fail
fnScoreHist(x=rnorm(86,150,20),lo=100,hi=200,gradeScheme="US",gradeBounds=c(55),pcScore=FALSE)
fnScoreHist(x=rnorm(86,150,20),lo=50,hi=200,gradeScheme="US",gradeBounds=c(55),pcScore=FALSE)
Outputs a ggplot object, which can them be editted as necessary.
plotExample<-fnScoreHist(x=rnorm(86,50,15),gradeScheme="US",gradeBounds=c(44))
plotExample # plot output
plotExample+ggtitle("Example Distribution of Assessment Scores") # plot output plus title
Written by Martin Roberts (psychometrics@plymouth.ac.uk)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.