Documentation for fxl
Drawing Hybrid/Blended Designs in R: Recreating Treatment Evaluation in Gilroy et al. (2019).
Written by Shawn P. Gilroy (Last Updated: 2024-06-02)Reversal DesignsMultiple Baseline DesignsAim LinesBracketsHybrid Figures
This posts follows from the previous Functional Analysis figure from Gilroy et al. (2021) to illustrate the Treatment Evaluation conducted in that study. The primary intervention evaluated was a Functional Communication Training approach extended by a novel schedule advancement strategy.
The final figure for this work is illustrated below:
Data Structure
There is a complex data structure for this figure. There is a column specific to challenging behavior (CTB = combined rates of target behavior), a Functional Communication Response for Attention (AFCR), and a Functional Communication Response for Escape (EFCR). There are Baseline and Intervention conditions; however, each must be distinguished from one another (e.g., “Intervention”, “Intervention2”) to ensure that data are linked into the correct groupings.
A preview of the relevant data is shown below:
head(csv_data)
## Function Session Condition CTB AFCR EFCR
## 1 Attention 3 Baseline 0.3 NA NA
## 2 Attention 7 Baseline 0.6 NA NA
## 3 Attention 12 Baseline 1.3 NA NA
## 4 Attention 16 Intervention 0.0 1.8 NA
## 5 Attention 17 Intervention 0.0 1.6 NA
## 6 Attention 20 Intervention 0.0 1.8 NA
Plot Elements
There is some pretty extensive formatting necessary to produce the final figure. Several new annotations are illustrated here–brackets for labeling a respective range (e.g., demand fading; scr_anno_brackets) and a guide line for highlighting behavior deceleration targets (scr_anno_guide_line).
The unmodified raw output of the data is presented below:
scr_plot(csv_data,
aesthetics = var_map(x = Session,
y = CTB,
p = Condition,
facet = Function
),
mai = c(0.375, 0.375, 0.25, .25),
omi = c(0.25, 0.25, 0.25, 0.25),
family = "Times New Roman") |>
scr_lines(size = 1) |>
scr_lines(mapping = list(x = Session,
y = AFCR),
size = 1,
lty = 2) |>
scr_lines(mapping = list(x = Session,
y = EFCR),
size = 1,
lty = 3) |>
scr_points(fill = "white",
pch = 21) |>
scr_points(mapping = list(x = Session,
y = AFCR),
cex = 1,
pch = 20,
fill = "black") |>
scr_points(mapping = list(x = Session,
y = EFCR),
cex = 0.75,
pch = 24,
fill = "black")
Axis and Tick Styling
This figure can be made much more understandable through editing relevant axes.
scr_plot(csv_data,
aesthetics = var_map(x = Session,
y = CTB,
p = Condition,
facet = Function
),
mai = c(0.375, 0.375, 0.25, .25),
omi = c(0.25, 0.25, 0.25, 0.25),
family = "Times New Roman") |>
scr_yoverride(
list(
"Attention" = list(
y0 = -0.125,
y1 = 3,
yticks = c(0, 1, 2, 3)
),
"Demand" = list(
y0 = -0.125,
y1 = 3,
yticks = c(0, 1, 2, 3)
)
)
) |>
scr_xoverride(c(-1, 100),
xdelta = 10,
xticks = c(1,
seq(10, 100,
by = 10))
) |>
scr_xlabel("Session",
adj = 0.5125,
cex = 1.15) |>
scr_ylabel("Combined Target Behavior (Per Minute)",
cex = 1.15,
adj = 0.65) |>
scr_lines(size = 1) |>
scr_lines(mapping = list(x = Session,
y = AFCR),
size = 1,
lty = 2) |>
scr_lines(mapping = list(x = Session,
y = EFCR),
size = 1,
lty = 3) |>
scr_points(fill = "white",
pch = 21) |>
scr_points(mapping = list(x = Session,
y = AFCR),
cex = 1,
pch = 20,
fill = "black") |>
scr_points(mapping = list(x = Session,
y = EFCR),
cex = 0.75,
pch = 24,
fill = "black")
Adding Phase Lines, Labels, Arrows
The figure becomes much more informative phase change lines (both single and multiple-baseline lines) and labels/arrows are included for respective facets, phases, and targets.
scr_plot(csv_data,
aesthetics = var_map(x = Session,
y = CTB,
p = Condition,
facet = Function
),
mai = c(0.375, 0.375, 0.25, .25),
omi = c(0.25, 0.25, 0.25, 0.25),
family = "Times New Roman") |>
scr_yoverride(
list(
"Attention" = list(
y0 = -0.125,
y1 = 3,
yticks = c(0, 1, 2, 3)
),
"Demand" = list(
y0 = -0.125,
y1 = 3,
yticks = c(0, 1, 2, 3)
)
)
) |>
scr_xoverride(c(-1, 100),
xdelta = 10,
xticks = c(1,
seq(10, 100,
by = 10))
) |>
scr_xlabel("Session",
adj = 0.5125,
cex = 1.15) |>
scr_ylabel("Combined Target Behavior (Per Minute)",
cex = 1.15,
adj = 0.65) |>
scr_lines(size = 1) |>
scr_lines(mapping = list(x = Session,
y = AFCR),
size = 1,
lty = 2) |>
scr_lines(mapping = list(x = Session,
y = EFCR),
size = 1,
lty = 3) |>
scr_points(fill = "white",
pch = 21) |>
scr_points(mapping = list(x = Session,
y = AFCR),
cex = 1,
pch = 20,
fill = "black") |>
scr_points(mapping = list(x = Session,
y = EFCR),
cex = 0.75,
pch = 24,
fill = "black") |>
scr_plines_mbd(
lines = list(
"A" = list(
"Attention" = list(
x1 = 13.5,
y1 = 3.15,
y2 = -0.125
),
"Demand" = list(
x1 = 20,
y1 = 3,
y2 = -0.125
)
)
)
) |>
scr_plines(lty = 1,
lines = list(
"Attention" = list(
"A" = list(
x1 = 25.5,
y1 = 3
),
"B" = list(
x1 = 26.5,
y1 = 3
),
"C" = list(
x1 = 60.5,
y1 = 3,
lty = 3
),
"D" = list(
x1 = 76.5,
y1 = 3,
lty = 3
)
),
"Demand" = list(
"A" = list(
x1 = 34.5,
y1 = 3
),
"B" = list(
x1 = 37.5,
y1 = 3
),
"C" = list(
x1 = 41.5,
y1 = 3
),
"D" = list(
x1 = 50.5,
y1 = 3,
lty = 3
),
"E" = list(
x1 = 72.5,
y1 = 3,
lty = 3
)
))) |>
scr_label_facet(cex = 1.25,
adj = 1,
y = 3.15,
x = 100,
labels = list("Attention",
"Demand")) |>
scr_label_phase(facet = "Attention",
cex = 0.8,
adj = 0.5,
y = 3,
labels = list(
"Baseline" = list(
x = 14,
y = 3.5
),
"FCR-A + EXT" = list(
x = 20
),
"FCR-A + EXT" = list(
x = 32
),
"Parent\nImplementation" = list(
x = 68.5
),
"Generalization" = list(
x = 83
),
"Problem Behavior" = list(
x = 7,
y = 1.8
),
"FCR-A" = list(
x = 20,
y = 2.5
),
"Add FCR\nOptions" = list(
x = 31,
y = 2.5
))) |>
scr_label_phase(facet = "Demand",
cex = 0.8,
adj = 0.5,
y = 3,
labels = list(
"FCR-E + EXT" = list(
x = 30,
y = 3.45
),
"FCR-A P = 0.1" = list(
x = 36,
y = 2,
srt = 90
),
"FCR-A/E + EXT" = list(
x = 47,
y = 3.35
),
"Parent Implementation" = list(
x = 61.5
),
"Generalization" = list(
x = 80
),
"FCR-E" = list(
x = 24,
y = 2.5
),
"FCR-A\nP = 0.1\n200% SR" = list(
x = 46,
y = 2
))) |>
scr_anno_arrows(facet = "Attention",
length = 0.1,
arrows = list(
"A" = list(
x0 = 7,
x1 = 7,
y0 = 1.5,
y1 = 1
),
"B" = list(
x0 = 20,
x1 = 20,
y0 = 2.25,
y1 = 2
),
"C" = list(
x0 = 31,
x1 = 31,
y0 = 2.25,
y1 = 2
))) |>
scr_anno_arrows(facet = "Demand",
length = 0.1,
arrows = list(
"A" = list(
x0 = 24,
x1 = 24,
y0 = 2.25,
y1 = 1.5
),
"B" = list(
x0 = 36,
x1 = 36,
y0 = 1.3,
y1 = 0.75
),
"C" = list(
x0 = 46,
x1 = 46,
y0 = 1.5,
y1 = 0.75
)))
Novel Features
There are two added features featured in this figure, brackets and guidelines.
Bracket Annotations
The scr_anno_brackets function is largely an extension of the scr_arrows function–essentially two line annotations connected by a line at the onset (i.e., x1/x2 and y1/y2 pairs).
The figure below displays how a bracketing convention can be used to identify a specific range of sessions (i.e., a starting and ending point; e.g., demand number, s delta interval).
scr_plot(csv_data,
aesthetics = var_map(x = Session,
y = CTB,
p = Condition,
facet = Function
),
mai = c(0.375, 0.375, 0.25, .25),
omi = c(0.25, 0.25, 0.25, 0.25),
family = "Times New Roman") |>
scr_yoverride(
list(
"Attention" = list(
y0 = -0.125,
y1 = 3,
yticks = c(0, 1, 2, 3)
),
"Demand" = list(
y0 = -0.125,
y1 = 3,
yticks = c(0, 1, 2, 3)
)
)
) |>
scr_xoverride(c(-1, 100),
xdelta = 10,
xticks = c(1,
seq(10, 100,
by = 10))
) |>
scr_xlabel("Session",
adj = 0.5125,
cex = 1.15) |>
scr_ylabel("Combined Target Behavior (Per Minute)",
cex = 1.15,
adj = 0.65) |>
scr_lines(size = 1) |>
scr_lines(mapping = list(x = Session,
y = AFCR),
size = 1,
lty = 2) |>
scr_lines(mapping = list(x = Session,
y = EFCR),
size = 1,
lty = 3) |>
scr_points(fill = "white",
pch = 21) |>
scr_points(mapping = list(x = Session,
y = AFCR),
cex = 1,
pch = 20,
fill = "black") |>
scr_points(mapping = list(x = Session,
y = EFCR),
cex = 0.75,
pch = 24,
fill = "black") |>
scr_plines_mbd(
lines = list(
"A" = list(
"Attention" = list(
x1 = 13.5,
y1 = 3.15,
y2 = -0.125
),
"Demand" = list(
x1 = 20,
y1 = 3,
y2 = -0.125
)
)
)
) |>
scr_plines(lty = 1,
lines = list(
"Attention" = list(
"A" = list(
x1 = 25.5,
y1 = 3
),
"B" = list(
x1 = 26.5,
y1 = 3
),
"C" = list(
x1 = 60.5,
y1 = 3,
lty = 3
),
"D" = list(
x1 = 76.5,
y1 = 3,
lty = 3
)
),
"Demand" = list(
"A" = list(
x1 = 34.5,
y1 = 3
),
"B" = list(
x1 = 37.5,
y1 = 3
),
"C" = list(
x1 = 41.5,
y1 = 3
),
"D" = list(
x1 = 50.5,
y1 = 3,
lty = 3
),
"E" = list(
x1 = 72.5,
y1 = 3,
lty = 3
)
))) |>
scr_label_facet(cex = 1.25,
adj = 1,
y = 3.15,
x = 100,
labels = list("Attention",
"Demand")) |>
scr_label_phase(facet = "Attention",
cex = 0.8,
adj = 0.5,
y = 3,
labels = list(
"Baseline" = list(
x = 14,
y = 3.5
),
"FCR-A + EXT" = list(
x = 20
),
"FCR-A + EXT" = list(
x = 32
),
"Parent\nImplementation" = list(
x = 68.5
),
"Generalization" = list(
x = 83
),
"Problem Behavior" = list(
x = 7,
y = 1.8
),
"FCR-A" = list(
x = 20,
y = 2.5
),
"Add FCR\nOptions" = list(
x = 31,
y = 2.5
))) |>
scr_label_phase(facet = "Attention",
cex = 0.8,
adj = 0.5,
labels = list(
"5s" = list(
x = 38.5,
y = 2.4
),
"Schedule Thinning" = list(
x = 53,
y = 2.4
),
"300s" = list(
x = 74.5,
y = 2.4
))) |>
scr_label_phase(facet = "Demand",
cex = 0.8,
adj = 0.5,
y = 3,
labels = list(
"FCR-E + EXT" = list(
x = 30,
y = 3.45
),
"FCR-A P = 0.1" = list(
x = 36,
y = 2,
srt = 90
),
"FCR-A/E + EXT" = list(
x = 47,
y = 3.35
),
"Parent Implementation" = list(
x = 61.5
),
"Generalization" = list(
x = 80
),
"FCR-E" = list(
x = 24,
y = 2.5
),
"FCR-A\nP = 0.1\n200% SR" = list(
x = 46,
y = 2
))) |>
scr_label_phase(facet = "Demand",
cex = 0.8,
adj = 0.5,
y = 1.375,
labels = list(
"1" = list(
x = 29.5
),
"Demand Fading" = list(
x = 58
),
"6" = list(
x = 71.5
))) |>
scr_anno_arrows(facet = "Attention",
length = 0.1,
arrows = list(
"A" = list(
x0 = 7,
x1 = 7,
y0 = 1.5,
y1 = 1
),
"B" = list(
x0 = 20,
x1 = 20,
y0 = 2.25,
y1 = 2
),
"C" = list(
x0 = 31,
x1 = 31,
y0 = 2.25,
y1 = 2
))) |>
scr_anno_arrows(facet = "Demand",
length = 0.1,
arrows = list(
"A" = list(
x0 = 24,
x1 = 24,
y0 = 2.25,
y1 = 1.5
),
"B" = list(
x0 = 36,
x1 = 36,
y0 = 1.3,
y1 = 0.75
),
"C" = list(
x0 = 46,
x1 = 46,
y0 = 1.5,
y1 = 0.75
))) |>
scr_anno_brackets(facet = "Attention",
length = 0.1,
brackets = list(
"A" = list(
x0 = 8,
x1 = 26,
y0 = 3.3,
y1 = 3
),
"B" = list(
x0 = 38,
x1 = 76,
y0 = 2.25,
y1 = 1.5,
lty = 3
)
)
) |>
scr_anno_brackets(facet = "Demand",
length = 0.1,
brackets = list(
"A" = list(
x0 = 23,
x1 = 40,
y0 = 3.3,
y1 = 3
),
"B" = list(
x0 = 36,
x1 = 47,
y0 = 3.2,
y1 = 2.9
),
"C" = list(
x0 = 29,
x1 = 72,
y0 = 1.25,
y1 = 0.5,
lty = 3
)))
Guide Line Annotations
The scr_anno_guide_line function is basically just a line drawn on the figure (i.e., similar to a phase change, just horizontal).
Guide lines are often included as a part of figures to indicate a relevant target for intervention (i.e., reduction of problem behavior levels to <90% of baseline). With this final component added, our figure is complete!
scr_plot(csv_data,
aesthetics = var_map(x = Session,
y = CTB,
p = Condition,
facet = Function
),
mai = c(0.375, 0.375, 0.25, .25),
omi = c(0.25, 0.25, 0.25, 0.25),
family = "Times New Roman") |>
scr_yoverride(
list(
"Attention" = list(
y0 = -0.125,
y1 = 3,
yticks = c(0, 1, 2, 3)
),
"Demand" = list(
y0 = -0.125,
y1 = 3,
yticks = c(0, 1, 2, 3)
)
)
) |>
scr_xoverride(c(-1, 100),
xdelta = 10,
xticks = c(1,
seq(10, 100,
by = 10))
) |>
scr_xlabel("Session",
adj = 0.5125,
cex = 1.15) |>
scr_ylabel("Combined Target Behavior (Per Minute)",
cex = 1.15,
adj = 0.65) |>
scr_lines(size = 1) |>
scr_lines(mapping = list(x = Session,
y = AFCR),
size = 1,
lty = 2) |>
scr_lines(mapping = list(x = Session,
y = EFCR),
size = 1,
lty = 3) |>
scr_points(fill = "white",
pch = 21) |>
scr_points(mapping = list(x = Session,
y = AFCR),
cex = 1,
pch = 20,
fill = "black") |>
scr_points(mapping = list(x = Session,
y = EFCR),
cex = 0.75,
pch = 24,
fill = "black") |>
scr_plines_mbd(
lines = list(
"A" = list(
"Attention" = list(
x1 = 13.5,
y1 = 3.15,
y2 = -0.125
),
"Demand" = list(
x1 = 20,
y1 = 3,
y2 = -0.125
)
)
)
) |>
scr_plines(lty = 1,
lines = list(
"Attention" = list(
"A" = list(
x1 = 25.5,
y1 = 3
),
"B" = list(
x1 = 26.5,
y1 = 3
),
"C" = list(
x1 = 60.5,
y1 = 3,
lty = 3
),
"D" = list(
x1 = 76.5,
y1 = 3,
lty = 3
)
),
"Demand" = list(
"A" = list(
x1 = 34.5,
y1 = 3
),
"B" = list(
x1 = 37.5,
y1 = 3
),
"C" = list(
x1 = 41.5,
y1 = 3
),
"D" = list(
x1 = 50.5,
y1 = 3,
lty = 3
),
"E" = list(
x1 = 72.5,
y1 = 3,
lty = 3
)
))) |>
scr_label_facet(cex = 1.25,
adj = 1,
y = 3.15,
x = 100,
labels = list("Attention",
"Demand")) |>
scr_label_phase(facet = "Attention",
cex = 0.8,
adj = 0.5,
y = 3,
labels = list(
"Baseline" = list(
x = 14,
y = 3.5
),
"FCR-A + EXT" = list(
x = 20
),
"FCR-A + EXT" = list(
x = 32
),
"Parent\nImplementation" = list(
x = 68.5
),
"Generalization" = list(
x = 83
),
"Problem Behavior" = list(
x = 7,
y = 1.8
),
"FCR-A" = list(
x = 20,
y = 2.5
),
"Add FCR\nOptions" = list(
x = 31,
y = 2.5
))) |>
scr_label_phase(facet = "Attention",
cex = 0.8,
adj = 0.5,
labels = list(
"5s" = list(
x = 38.5,
y = 2.4
),
"Schedule Thinning" = list(
x = 53,
y = 2.4
),
"300s" = list(
x = 74.5,
y = 2.4
))) |>
scr_label_phase(facet = "Demand",
cex = 0.8,
adj = 0.5,
y = 3,
labels = list(
"FCR-E + EXT" = list(
x = 30,
y = 3.45
),
"FCR-A P = 0.1" = list(
x = 36,
y = 2,
srt = 90
),
"FCR-A/E + EXT" = list(
x = 47,
y = 3.35
),
"Parent Implementation" = list(
x = 61.5
),
"Generalization" = list(
x = 80
),
"FCR-E" = list(
x = 24,
y = 2.5
),
"FCR-A\nP = 0.1\n200% SR" = list(
x = 46,
y = 2
))) |>
scr_label_phase(facet = "Demand",
cex = 0.8,
adj = 0.5,
y = 1.375,
labels = list(
"1" = list(
x = 29.5
),
"Demand Fading" = list(
x = 58
),
"6" = list(
x = 71.5
))) |>
scr_anno_arrows(facet = "Attention",
length = 0.1,
arrows = list(
"A" = list(
x0 = 7,
x1 = 7,
y0 = 1.5,
y1 = 1
),
"B" = list(
x0 = 20,
x1 = 20,
y0 = 2.25,
y1 = 2
),
"C" = list(
x0 = 31,
x1 = 31,
y0 = 2.25,
y1 = 2
))) |>
scr_anno_arrows(facet = "Demand",
length = 0.1,
arrows = list(
"A" = list(
x0 = 24,
x1 = 24,
y0 = 2.25,
y1 = 1.5
),
"B" = list(
x0 = 36,
x1 = 36,
y0 = 1.3,
y1 = 0.75
),
"C" = list(
x0 = 46,
x1 = 46,
y0 = 1.5,
y1 = 0.75
))) |>
scr_anno_brackets(facet = "Attention",
length = 0.1,
brackets = list(
"A" = list(
x0 = 8,
x1 = 26,
y0 = 3.3,
y1 = 3
),
"B" = list(
x0 = 38,
x1 = 76,
y0 = 2.25,
y1 = 1.5,
lty = 3
)
)
) |>
scr_anno_brackets(facet = "Demand",
length = 0.1,
brackets = list(
"A" = list(
x0 = 23,
x1 = 40,
y0 = 3.3,
y1 = 3
),
"B" = list(
x0 = 36,
x1 = 47,
y0 = 3.2,
y1 = 2.9
),
"C" = list(
x0 = 29,
x1 = 72,
y0 = 1.25,
y1 = 0.5,
lty = 3
))) |>
scr_anno_guide_line(color = "red",
lty = 3,
facet = "Attention",
coords = list(
"A" = list(
x0 = 14,
x1 = 25.5,
y0 = 0.1
),
"B" = list(
x0 = 26.5,
x1 = 100,
y0 = 0.1
))) |>
scr_anno_guide_line(color = "red",
lty = 3,
facet = "Demand",
coords = list(
"A" = list(
x0 = 20,
x1 = 100,
y0 = 0.1
)))