Hello,

I's still working with my tsibble of weight data for the last 20 years. 
In addition to drawing an overall trend line, using lm, for the whole 
data set, I'd like to draw short lines that would recompute lm and draw 
it, say, just for the years from 2010:2015.

Here's a short example that I think illustrates what I'm trying to do. 
The commented out sections show what I've tried to far:

## Short example to test segments:

w <- tsibble(
     date = as.Date("2022-01-01") + 0:99,
     value = rnorm(100)
)

ggplot(data = w, mapping = aes(date, value)) +
     geom_smooth(method = "lm", se = FALSE) +
     geom_point()
     ## Below gives error about ignoring data
     ## geom_abline( data = w$date[25:75] )
     ## Gives error ''data' must be in <data.frame>'
     ## geom_smooth(data = w$date[25:35],
     ##             method = lm,
     ##             color = "black",
     ##             se = FALSE)

I'm thinking that this is probably easily done, but I'm struggling with 
how to subset the data in the middle of the pipeline.

Thanks for any advice and help.

-Kevin

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to