Package 'snp'

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

Help Index


Plot the standard normal curve with score scales

Description

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.

Usage

plot_normal(
  scales = standard_normal_scales_data(),
  size = 3,
  palette = c("blues", "reds", "greens", "diverging"),
  mode = c("light", "dark")
)

Arguments

scales

A data frame with one row per tick mark or band, and the columns:

scale

Name of the scale, shown at the left of its row. Rows are drawn from top to bottom in the order the names first appear.

z

Position on the z axis: where the tick mark goes, or where the band starts.

label

Text shown at the tick mark or inside the band.

z_end

Optional. Where the band ends on the z axis. Leave the column out, or use NA, for a tick mark.

colour

Optional. Fill colour of the band. Bands without a colour take the colours of palette.

The default, standard_normal_scales_data(), holds the standard scales; its help page says how each one is defined.

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:

"blues", "reds" or "greens"

One colour, which shows how common a score is: under the curve, the intervals that hold more cases are darker, so 34.13% is the darkest and 0.13% the lightest, and the bands are darker the nearer the mean they are.

"diverging"

A neutral gray under the curve, and bands blue below the mean and red above it, darker the further from the mean, with gray for a band centred on the mean.

mode

"light" for dark text on a white background, or "dark" for light text on a near-black background. In the dark mode the colours that are darker in the light mode are brighter instead, so that they still stand out from the background.

Details

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.

Value

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.

See Also

standard_normal_scales_data, plot_normal_height

Examples

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)

The height that fits a chart

Description

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().

Usage

plot_normal_height(
  plot = plot_normal(),
  width = 7,
  units = c("in", "cm", "mm")
)

Arguments

plot

A chart of plot_normal, or any ggplot with a fixed aspect ratio.

width

The width of the figure.

units

The units of width and of the height returned: "in", "cm" or "mm".

Details

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.

Value

The height, a number in units.

See Also

plot_normal

Examples

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))

Score scales of the standard normal chart, as a data frame

Description

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.

Usage

standard_normal_scales_data()

Details

All scales are placed on the z axis:

  • z: standard score, mean 0 and standard deviation 1.

  • T: 50+10z50 + 10z.

  • Cumulative %: the percentage of cases below each standard deviation, from z=−3z = -3 to z=3z = 3: 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 z=−2z = -2 and sten 10 above z=2z = 2 (mean 5.5, standard deviation 2).

  • Stanine: nine bands half a standard deviation wide, stanine 5 from z=−0.25z = -0.25 to z=0.25z = 0.25 (mean 5, standard deviation 2).

  • Grade: groups of stanines, E (1-2), D (3), C (4-6), B (7) and A (8-9).

  • IQ: 100+15z100 + 15z.

Value

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.

See Also

plot_normal

Examples

scales<-standard_normal_scales_data()
head(scales)
unique(scales$scale)