Skip to content

Issue587#588

Merged
grantmcdermott merged 3 commits into
mainfrom
issue587
May 15, 2026
Merged

Issue587#588
grantmcdermott merged 3 commits into
mainfrom
issue587

Conversation

@grantmcdermott
Copy link
Copy Markdown
Owner

@grantmcdermott grantmcdermott commented May 15, 2026

Fixes #587

No NEWS item since it was in-dev regression.

pkgload::load_all("~/Documents/Projects/tinyplot/")
#> ℹ Loading tinyplot
aq = airquality
aq$Month = factor(month.name[aq$Month], levels = month.name[5:9])

tinytheme("clean2")
# base layer
plt(Temp ~ Day | Month, data = aq, type = "l", legend = FALSE)

# for labels: subset to final dates for each month 
aq2 = aq[aq$Day == ave(aq$Day, aq$Month, FUN = max), ]

# add the labels with a type_text() layer
plt_add(data = aq2, type = "text", labels = aq2$Month,
        pos = 4, offset = 0.2, xpd = NA)

# Fix: first grab the theme params and then adjust the RHS margin by
# the longest label in the dataset
longest_lab = max(strwidth(as.character(aq2$Month)))/2 # divide by 2 to get lines
parms = tinyplot:::theme_clean2
parms$mar[4] = parms$mar[4] + longest_lab
tinytheme("clean2", mar = parms$mar) # theme with adjusted margins

# Now plot both the base and direct label layers
plt(Temp ~ Day | Month, data = aq, type = "l", legend = FALSE)
plt_add(data = aq2, type = "text", labels = aq2$Month,
        pos = 4, offset = 0.2, xpd = NA)

Created on 2026-05-15 with reprex v2.1.1

@grantmcdermott grantmcdermott merged commit 86734de into main May 15, 2026
3 checks passed
@grantmcdermott grantmcdermott deleted the issue587 branch May 15, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vignettes: direct labels example no longer working

1 participant