| Title: | Plot standard normal distribution |
|---|---|
| Description: | Draws the standard normal curve with score scales lined up under it: z, T, cumulative percentage, percentile, sten, stanine, grade and IQ, or scales defined in a data frame, each shown as labelled tick marks or coloured bands, in blues, reds, greens or a diverging palette, each with a light and a dark mode. |
| Authors: | Dimitrios Zacharatos [aut, cre] (ORCID: <https://orcid.org/0000-0003-1789-8294>) |
| Maintainer: | Dimitrios Zacharatos <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-11-19 18:40:57 UTC |
| Source: | https://github.com/sedzinfo/snp |
Draws the standard normal curve, divided at every standard deviation and marked with the percentage of cases in each interval, with score scales lined up under it, so that a score on one scale can be read off on the others: by default the z, T, cumulative percentage, percentile, sten, stanine, grade and IQ scales, or scales you describe in a data frame. A scale can be a row of labelled tick marks (like T scores), a row of coloured bands (like stanines), or both.
plot_normal( scales = standard_normal_scales_data(), size = 3, palette = c("blues", "reds", "greens", "diverging"), mode = c("light", "dark") )plot_normal( scales = standard_normal_scales_data(), size = 3, palette = c("blues", "reds", "greens", "diverging"), mode = c("light", "dark") )
scales |
A data frame with one row per tick mark or band, and the columns:
The default, |
size |
Text size of all labels, in millimetres (ggplot2 text size). The default of 3 suits figures around 7 inches wide; about 5 suits figures around 12 inches wide. |
palette |
The colours of the chart:
|
mode |
|
The labels on the coloured areas are white or near-black, whichever stands out more
from the colour behind them. The names of the scales are in a column of their own, just
left of the scales, so a long name never runs into them. The percentages are on one line,
each over its interval, raised from the base of the curve by heights of their text, so that
they keep their place whatever the size of the figure. The lines, the gaps between
the bands and their rounded corners grow with size, as the text does.
A ggplot object. Print it to draw the chart, or save it with
ggplot2::ggsave(). The chart keeps a fixed aspect ratio, and every scale you add
makes it taller. With the default scales it is about 2.2 times as wide as it is tall, so a
figure with those proportions, such as 7 by 3.2 inches, has no empty margins;
plot_normal_height gives the height that fits any chart exactly.
standard_normal_scales_data, plot_normal_height
plot_normal() plot_normal(palette="reds") plot_normal(palette="greens",mode="dark") plot_normal(size=5) # save it with the chart's proportions ggsave(file.path(tempdir(),"plot_normal.png"),plot_normal(),width=7,height=3.2) # your own scales: tick marks for a test score and bands for performance levels my_scales<-rbind(data.frame(scale="SCORE",z=-3:3,z_end=NA,label=seq(20,80,10)), data.frame(scale="LEVEL",z=c(-4,-1,1),z_end=c(-1,1,4), label=c("Low","Average","High"))) plot_normal(my_scales,palette="diverging") # start from the standard scales, drop the grades and add Wechsler scaled scores (mean 10, SD 3) scales<-standard_normal_scales_data() scales<-scales[scales$scale!="GRADE",] scales<-rbind(scales,data.frame(scale="SCALED",z=-3:3,z_end=NA,label=seq(1,19,3),colour=NA)) plot_normal(scales)plot_normal() plot_normal(palette="reds") plot_normal(palette="greens",mode="dark") plot_normal(size=5) # save it with the chart's proportions ggsave(file.path(tempdir(),"plot_normal.png"),plot_normal(),width=7,height=3.2) # your own scales: tick marks for a test score and bands for performance levels my_scales<-rbind(data.frame(scale="SCORE",z=-3:3,z_end=NA,label=seq(20,80,10)), data.frame(scale="LEVEL",z=c(-4,-1,1),z_end=c(-1,1,4), label=c("Low","Average","High"))) plot_normal(my_scales,palette="diverging") # start from the standard scales, drop the grades and add Wechsler scaled scores (mean 10, SD 3) scales<-standard_normal_scales_data() scales<-scales[scales$scale!="GRADE",] scales<-rbind(scales,data.frame(scale="SCALED",z=-3:3,z_end=NA,label=seq(1,19,3),colour=NA)) plot_normal(scales)
Returns the height of a figure that a chart of plot_normal fills
exactly at a given width, with no empty margins, to save it with ggplot2::ggsave().
plot_normal_height( plot = plot_normal(), width = 7, units = c("in", "cm", "mm") )plot_normal_height( plot = plot_normal(), width = 7, units = c("in", "cm", "mm") )
plot |
A chart of |
width |
The width of the figure. |
units |
The units of |
The chart keeps a fixed aspect ratio, but the column of the names of the scales, the text and the margins keep their size whatever the size of the figure, so the height that fits depends on the width, on the number of scales and on the length of their names. The function lays the chart out at the given width, measuring its text as a PDF does, and adds up the heights. Other graphics devices measure text a little differently, which can leave a margin of a fraction of a millimetre.
The height, a number in units.
plot_normal_height(plot_normal(), 7) plot_normal_height(plot_normal(), 17.8, units = "cm") # fewer scales, a shorter chart scales <- standard_normal_scales_data() p <- plot_normal(scales[scales$scale %in% c("z", "T", "IQ"), ]) plot_normal_height(p, 7) ggsave(file.path(tempdir(), "normal.pdf"), p, width = 7, height = plot_normal_height(p, 7))plot_normal_height(plot_normal(), 7) plot_normal_height(plot_normal(), 17.8, units = "cm") # fewer scales, a shorter chart scales <- standard_normal_scales_data() p <- plot_normal(scales[scales$scale %in% c("z", "T", "IQ"), ]) plot_normal_height(p, 7) ggsave(file.path(tempdir(), "normal.pdf"), p, width = 7, height = plot_normal_height(p, 7))
Returns the z, T, cumulative percentage, percentile, sten, stanine, grade and
IQ scales that plot_normal draws by default, in the format of its
scales argument, so you can start from them and change, remove or add scales.
standard_normal_scales_data()standard_normal_scales_data()
All scales are placed on the z axis:
z: standard score, mean 0 and standard deviation 1.
T: .
Cumulative %: the percentage of cases below each standard deviation, from
to : 0.1, 2.3, 15.9, 50, 84.1, 97.7 and 99.9.
Percentile: the z values of the 1st, 5th, 10th, 25th, 50th, 75th, 90th, 95th and 99th percentiles.
Sten: ten bands half a standard deviation wide, sten 1 below
and sten 10 above (mean 5.5, standard deviation 2).
Stanine: nine bands half a standard deviation wide, stanine 5 from
to (mean 5, standard deviation 2).
Grade: groups of stanines, E (1-2), D (3), C (4-6), B (7) and A (8-9).
IQ: .
A data frame with the columns scale, z, z_end, label and colour, and one row per
tick mark (z, T, cumulative percentage, percentile and IQ, with z_end set to
NA) or per band (sten, stanine and grade). colour is NA throughout, so
that the bands take the colours of the palette of the chart; set it to colour a band
yourself.
scales<-standard_normal_scales_data() head(scales) unique(scales$scale)scales<-standard_normal_scales_data() head(scales) unique(scales$scale)