[R] how to make the far right section of a smoother line look different from the rest of that line?

Christopher W Ryan cry@n @end|ng |rom b|ngh@mton@edu
Tue Nov 16 16:44:53 CET 2021


eclrs.3 %>%
mutate(start.week = floor_date(realCollectionDate, unit = "week")) %>%
group_by(start.week, k12) %>%
summarise(n = n(), pctpos = 100 * mean(realResult))  %>%
xyplot(pctpos ~ start.week | k12, col = "red", data = ., layout = c(1,2),
ylab = "percent of test results positive", xlab = "specimen collection
date",  strip = strip.custom(strip.names = c(TRUE, TRUE)),  sub = "The
final week shown may not yet be complete so is likely inaccurate",   panel
= function(...){
    panel.xyplot(..., type = "p", cex = 0.8)
    panel.smoother(..., span = 0.3, col.se = "red", alpha.se = 0.08, lwd =
2)})

The above takes patient-level data, each record containing a date, and
aggregates them by week according to that date, then plots 2 weekly time
series, one for k12 and one for not-k12, each with a smoother. Note my
disclaimer in the subtitle that "the final week shown may not yet be
complete . . . ." since I might run this on any arbitrary day. How might I
change the appearance of the smoother lines to emphasize to the viewer that
the recent trends are tentative due to daily data still coming in?  For
example, how might I make the far right-end stretch of the lines,
representing the most recent week or two, dotted?

Thanks.

--Chris Ryan

	[[alternative HTML version deleted]]



More information about the R-help mailing list