gg_pta: Make a primer for pure tone audiograms with ggplot2

Description Usage Arguments Details Value Author(s) Examples

View source: R/gg_pta.R

Description

Call this to start building a plot based on pure tone audiometry.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
gg_pta(
  data = data.frame(),
  theme = theme_light,
  lettermark = NULL,
  lettermarksize = 30,
  xlab = "Frequency in Hertz (Hz)",
  ylab = "Hearing Levels in Decibels (dB)",
  xlim = c(125, 8000),
  xbreaks = c(125, 250, 500, 1000, 2000, 4000, 8000),
  minor_xbreaks = c(750, 1500, 3000),
  x_base_lwd = 1,
  xlabels = c("125", "250", "500", "1000", "2000", "4000", "8000"),
  ylim = c(120, -10),
  yposition = "left"
)

Arguments

data

data.frame that contains the data, later to be added to the plot. If no such data.frame is available, can be data = data.frame(0)

theme

theme for plotting in ggplot2. Can be set to NULL. A different theme can always be added later

lettermark

either "R" or "L" or c("R", "L") to add a letter describing the left or right side (see lettermarksize)

lettermarksize

size of letter for lettermark

xlab

string containing the x axis label

ylab

string containing the y axis label

xlim

limits of the frequencies displayed at the x axis.

xbreaks

frequencies at which major line breaks should be drawn. Must be of same length as xlabels

minor_xbreaks

frequencies at which minor line breaks should be drawn

x_base_lwd

if positive, a line to mark the 0 dB threshold level is drawn, the line width of which is given by x_base_lwd. Set to -1 to turn the line of

xlabels

vector of strings as frequency axis labels. Must be of same length as xbreaks.

ylim

limits of the decibels on the y axis

yposition

side on which to label the y axis: either "right" or "left"

Details

This function is called instead of ggplot2::ggplot with a data.frame and will return a ggplot with fixed axes, fixed axis ratio, ...

Value

a ggplot with standard axis ratio, given axis etc. to add geoms to

Author(s)

Bernhard Lehnert

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library(ggplot2)
fig1 <- gg_pta(data.frame())
print(fig1)

fig2 <- gg_pta(data.frame(), xlab="Frequency [Hz]", xlim=c(125,12000),
               xbreaks = c(125, 250, 500, 1000, 2000, 4000, 8000, 12000),
               xlabels = c("125", "250", "500", "1k", "2k", "4k", "8k", "12k"))
print(fig2)

expl <- data.frame(x=rep(c(500, 1000, 2000, 4000), 200),
                   y=5 + 70*rbeta(200,1,5))
fig3 <- gg_pta(expl, lettermark = "R",
               xlab="frecuencia", ylab="volumen") +
             geom_boxplot(aes(x=x, y=y, group=x)) +
             theme_grey()
print(fig3)

Example output



audiometry documentation built on June 2, 2021, 5:07 p.m.