
UC San Diego
COGS 137 - Fall 2026
2026-10-14
Q: Why was there a problem with the police not knowing whether the participants ingested a placebo, lower percentage, or higher percentage of THC?
A: I was not as clear as I should have been in this! The police knew that some participants received a placebo and some did not (that’s fine!), but they also knew how long it had been since they had smoked the joint. So, they would have expected (given knowing this information) that at each subsequent field sobriety test that they should maybe expect fewer and fewer participants to be impaired. Given unlimited resources, a more ideal design would have been to bring officers in randomly, without them knowing how far along the study was, so they didn’t have any expectation/knowledge about how recently someone could have smoked (which is the case at the roadside…they don’t know)
Q: confused about the cutoffs - what do they mean
A: The cutoffs are if we used that cutoff to determine someone had recently used then how many people would be “over the limit.”
Q: could you make a list or link where i can read or see more about different ggplot resources?
A: Some people find tidyverse cheat sheets particulrly helpful: https://opensource.posit.co/resources/cheatsheets/data-visualization/. Chapter 9 of our textbook also goes through the basics: https://r4ds.hadley.nz/layers.html. There are a lot of additional resources - if others have found some they really like, please share!
Due Dates:
Notes:





Today we’ll apply each of these to our CS01 data.
The cleaned, combined CS01 data (the same data/cs01_combined.csv that’s in your lab03 repo):
How many blood samples were collected in each time window?
🧠 What’s wrong with this order? Why did it happen?
clean_cs01() made timepoint a factor with levels in time orderread_csv() reads timepoint back in as a character variableggplot2 sorts character variables alphabetically: “101-180 min” comes before “31-70 min”, and “pre-smoking” ends up lastYou will run into this in CS01. Fix it once, right after reading in the data.
Overlapping labels are hard to read
So time reads from top to bottom:
🧠 Why might some windows have more samples than others?
For the rest of today: blood THC in the first window after smoking.
Doses are in alphabetical order (“13.4%” before “5.9%” before “Placebo”).
log(0) is -Inf"pseudo_log" acts like a log scale for large values and handles zeros🧠 Which plot better answers “Do frequent users have higher blood THC than occasional users?” Which better answers “Does dose matter?”
Same first window, three matrices (THC-treated participants only):


The legend repeats the y-axis labels:

ggplot(wb_early, aes(x = thc, y = treatment, fill = treatment)) +
geom_boxplot() +
scale_x_continuous(transform = "pseudo_log", breaks = c(0, 1, 10, 100)) +
scale_fill_manual(values = c("Placebo" = "#deebf7",
"5.9% THC (low dose)" = "#9ecae1",
"13.4% THC (high dose)" = "#3182bd")) +
guides(fill = "none")
ggplot(wb_early, aes(x = thc, y = treatment, fill = treatment)) +
geom_boxplot() +
scale_x_continuous(transform = "pseudo_log", breaks = c(0, 1, 10, 100)) +
scale_fill_manual(values = c("Placebo" = "#deebf7",
"5.9% THC (low dose)" = "#9ecae1",
"13.4% THC (high dose)" = "#3182bd")) +
guides(fill = "none") +
labs(
title = "Blood THC in the first 30 minutes after smoking",
subtitle = "Whole blood samples, 0-30 minutes after smoking began",
x = "THC (ng/mL, pseudo-log scale)",
y = NULL,
caption = "Data: CS01 (Hubbard et al., 2021)"
)
ggplot(wb_early, aes(x = thc, y = treatment, fill = treatment)) +
geom_boxplot() +
scale_x_continuous(transform = "pseudo_log", breaks = c(0, 1, 10, 100)) +
scale_fill_manual(values = c("Placebo" = "#deebf7",
"5.9% THC (low dose)" = "#9ecae1",
"13.4% THC (high dose)" = "#3182bd")) +
guides(fill = "none") +
labs(
title = "Blood THC in the first 30 minutes after smoking",
subtitle = "Whole blood samples, 0-30 minutes after smoking began",
x = "THC (ng/mL, pseudo-log scale)",
y = NULL,
caption = "Data: CS01 (Hubbard et al., 2021)"
) +
theme_minimal(base_size = 16) +
theme(plot.title.position = "plot",
panel.grid.major.y = element_blank())🧠 What do you notice about the low vs. high dose? What might explain it? (Think back to the smoking topography slides from the CS01 intro.)

ggplot(wb_early, aes(x = thc, y = treatment, fill = treatment)) +
geom_boxplot(outlier.shape = NA) +
geom_jitter(height = 0.15, alpha = 0.4, size = 1) +
scale_x_continuous(transform = "pseudo_log", breaks = c(0, 1, 10, 100)) +
scale_fill_manual(values = c("Placebo" = "#deebf7",
"5.9% THC (low dose)" = "#9ecae1",
"13.4% THC (high dose)" = "#3182bd")) +
guides(fill = "none") +
labs(
title = "Blood THC was no higher in the high dose group",
subtitle = "Whole blood samples, 0-30 minutes after smoking began",
x = "THC (ng/mL, pseudo-log scale)",
y = NULL,
caption = "Data: CS01 (Hubbard et al., 2021)"
) +
theme_minimal(base_size = 16) +
theme(plot.title.position = "plot",
panel.grid.major.y = element_blank())What we covered (cite these by name in your homework and case studies):
New data! In September 2019, a YouGov survey asked 1,639 GB adults: In hindsight, do you think Britain was right/wrong to vote to leave EU? (Right to leave / Wrong to leave / Don’t know)
brexit <- tibble(
opinion = c(
rep("Right", 664), rep("Wrong", 787), rep("Don't know", 188)
),
region = c(
rep("london", 63), rep("rest_of_south", 241), rep("midlands_wales", 145), rep("north", 176), rep("scot", 39),
rep("london", 110), rep("rest_of_south", 257), rep("midlands_wales", 152), rep("north", 176), rep("scot", 92),
rep("london", 24), rep("rest_of_south", 49), rep("midlands_wales", 57), rep("north", 48), rep("scot", 10)
)
)ggplot2?