README.md

chancedegol

library(chancedegol)
library(dplyr)
library(tidyr)
library(ggplot2)
data(cdg)

cdg %>%
  separate(placar, c('gols_mandante', 'gols_visitante'),
           sep = 'x', remove = TRUE, convert = TRUE) %>%
  mutate(gols = gols_mandante + gols_visitante) %>%
  group_by(ano) %>%
  summarise(jogos = n(),
            s = sd(gols),
            gols = mean(gols),
            upper = gols + qnorm(.975) * s / sqrt(jogos),
            lower = gols - qnorm(.975) * s / sqrt(jogos)) %>%
  ggplot(aes(x = ano, y = gols)) +
  geom_point() +
  geom_line() +
  theme_bw() +
  scale_x_continuous(breaks = 2001:2015) +
  geom_text(aes(label = jogos, y = 3.5)) +
  geom_errorbar(aes(ymin = lower, ymax = upper), width = .2)



jtrecenti/chancedegol documentation built on May 20, 2019, 3:16 a.m.