library(rtemis.draw).:rtemis.draw 0.1.0 🖌 aarch64-apple-darwin20
Attaching package: 'rtemis.draw'
The following object is masked from 'package:graphics':
Axis
.:rtemis.draw 0.1.0 🖌 aarch64-apple-darwin20
Attaching package: 'rtemis.draw'
The following object is masked from 'package:graphics':
Axis
Important Note that this vignette has been built using the light theme. The page theme toggle will work partly to switch the chart theme, but the result is not the same as using the dark theme directly. When working with an IDE like VS Code, if you don’t define a theme, the function will auto-detect your system setting and apply the appropriate theme.
We’ll use the built-in penguins dataset. Let’s take a look at the variables:
'data.frame': 344 obs. of 8 variables:
$ species : Factor w/ 3 levels "Adelie","Chinstrap",..: 1 1 1 1 1 1 1 1 1 1 ...
$ island : Factor w/ 3 levels "Biscoe","Dream",..: 3 3 3 3 3 3 3 3 3 3 ...
$ bill_len : num 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42 ...
$ bill_dep : num 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...
$ flipper_len: int 181 186 195 NA 193 190 181 195 193 190 ...
$ body_mass : int 3750 3800 3250 NA 3450 3650 3625 4675 3475 4250 ...
$ sex : Factor w/ 2 levels "female","male": 2 1 1 NA 1 2 1 2 NA NA ...
$ year : int 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 ...
Input: Single numeric vector
Note:
NAs, prints a message, and excludes them from the plotYou can define a custom label either by passing a named list/data.frame or by using the labels argument:
2026-04-28 05:16:09 Removed 2 NA values [FUN]
2026-04-28 05:16:09 Removed 2 NA values [FUN]
Input can be a list of any number of numeric vectors:
2026-04-28 05:16:09 Removed 2 NA values [FUN]
2026-04-28 05:16:09 Removed 2 NA values [FUN]
or a data.frame:
2026-04-28 05:16:09 Removed 2 NA values [FUN]
2026-04-28 05:16:09 Removed 2 NA values [FUN]
2026-04-28 05:16:10 Removed 2 NA values from data [draw_boxplot]
Use the breaks argument to control binning — it accepts any value accepted by graphics::hist(): a number of bins, a character algorithm name, or an explicit vector of break points:
2026-04-28 05:16:10 Removed 2 NA values from x [draw_density]
2026-04-28 05:16:10 Removed 2 NA values from x [draw_density]
2026-04-28 05:16:10 Removed 2 NA values from Body Mass [FUN]
Pass fit = "gam" (or "glm") to overlay a fitted line with a 95% confidence band:
Fit lines and confidence bands are drawn per group and share the group’s color. Clicking a legend entry toggles the scatter points, fit line, and band together:
Pass a named list to y to draw one line per element:
Set rose_type = "radius" to encode value as radius instead of arc angle:
draw_heatmap() accepts any numeric matrix. For square matrices, square_cells is enabled automatically so every cell is perfectly square.
Set zlim = c(-1, 1) to fix the color scale to the full correlation range:
For symmetric matrices it is common to show only one triangle. Use triangle = "lower" to keep the lower triangle and diagonal, masking the upper triangle:
Set show_values = TRUE to print each correlation coefficient inside its cell. value_digits controls the number of decimal places:
cluster_rows and cluster_cols reorder the matrix using hclust(), grouping similar rows and columns together:
For rectangular matrices, set square_cells = FALSE. Here we compute the mean of each trait per species and z-score the columns so traits on different scales are directly comparable:
traits <- c("bill_len", "bill_dep", "flipper_len", "body_mass")
means <- sapply(
traits,
function(tr) tapply(penguins[[tr]], penguins$species, mean, na.rm = TRUE)
)
colnames(means) <- c("Bill Length", "Bill Depth", "Flipper Length", "Body Mass")
draw_heatmap(
scale(means),
square_cells = FALSE,
show_values = TRUE,
value_digits = 2,
title = "Mean Traits by Species (z-scored)"
)draw_spectrogram() renders an interactive time–frequency heatmap. Pass a raw numeric signal vector together with sample_rate; the function computes the STFT internally via signal::specgram(). Alternatively pass a pre-computed spectrogram matrix directly.
All examples below use synthetic signals so no external data is required.
A chirp sweeps linearly from a low to a high frequency. The spectrogram makes the sweep immediately visible as a diagonal ridge:
Three simultaneous sine waves appear as three horizontal bands — one per frequency:
Use freq_scale = "log" to expand the low-frequency region — useful when the signal of interest spans several octaves. freq_unit = "kHz" and time_unit = "ms" rescale the axis labels:
For signed data — such as an Event-Related Spectral Perturbation (ERSP) matrix from an EEG experiment — use palette = "diverging". The midpoint colour maps exactly to zero. Set db = FALSE because the values are already on a meaningful signed scale:
set.seed(1)
n_freq <- 60
n_time <- 120
freq <- seq(4, 80, length.out = n_freq) # 4 – 80 Hz
time <- seq(-0.5, 1.5, length.out = n_time) # −500 ms to +1500 ms
# Background: small random fluctuations
ersp <- matrix(rnorm(n_freq * n_time, sd = 0.4), nrow = n_freq)
# Alpha suppression (8–13 Hz, 200–800 ms post-stimulus)
alpha_f <- freq >= 8 & freq <= 13
alpha_t <- time >= 0.2 & time <= 0.8
ersp[alpha_f, alpha_t] <- ersp[alpha_f, alpha_t] - 2.5
# Gamma increase (40–60 Hz, 100–400 ms post-stimulus)
gamma_f <- freq >= 40 & freq <= 60
gamma_t <- time >= 0.1 & time <= 0.4
ersp[gamma_f, gamma_t] <- ersp[gamma_f, gamma_t] + 2
draw_spectrogram(
ersp,
frequency = freq,
time = time,
db = FALSE,
power = FALSE,
palette = "diverging",
title = "Simulated ERSP"
)The seewave package includes several bird song recordings as Wave objects ready to pass to draw_spectrogram():
For EEG and physiological signals, PhysioNet (physionet.org) hosts thousands of freely downloadable recordings. The EDF/EDF+ format can be read into R with the edfReader package.