Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. qf6 = readRDS("~/Downloads/qf6.rds") %>%
  2. na.omit %>% arrange(name, month) %>% group_by(name) %>% mutate(lmonth=lead(month), lperc=lead(perc), lntot=lead(ntot))
  3.  
  4. avg = function(x, leadx, frac) ifelse(frac == 0, x, frac * leadx + (1-frac) * x)
  5.  
  6. steps = tibble(day=0:31)
  7. qf6b = crossing(qf6, steps) %>% mutate(x=month + day) %>% filter(day == 0 | (!is.na(lmonth) & x < lmonth)) %>%
  8. group_by(name, month) %>% mutate(frac=day/(max(day)+1)) %>% mutate(perc2=avg(perc, lperc, frac), ntot2=avg(ntot, lntot, frac))
  9.  
  10. ggplot(data=qf6b, aes(x=x, y=perc2, group=name, colour=factor(name), alpha=ifelse(ntot2>100, 100, ntot2))) +
  11. geom_line(size=1.2)+
  12. scale_x_date(date_breaks = "2 month") +
  13. xlab("Datum") +
  14. ylab("% Bron in het nieuws")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement