ITADN

Vignettes: direct labels example no longer working

#587Closedgrantmcdermott 创建于 2026-05-15
G
grantmcdermottcommented
Here: https://grantmcdermott.com/tinyplot/vignettes/tips.html#direct-labels Probably a regression that was missed from #549. ``` r library(tinyplot) tinytheme("clean2") aq = airquality aq$Month = factor(month.name[aq$Month], levels = month.name[5:9]) # 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) ``` ![](https://i.imgur.com/a0L1LU4.png)<!-- --> ``` r # 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) ``` ![](https://i.imgur.com/hRtYnI2.png)<!-- --> <sup>Created on 2026-05-15 with [reprex v2.1.1](https://reprex.tidyverse.org)</sup>
关闭于 2026-05-15 0 条评论