I have the following dataset:
library(babynames)
hadley <- dplyr::filter(babynames, name == "Hadley")
    year   sex   name     n         prop
   <dbl> <chr>  <chr> <int>        <dbl>
1   1906     M Hadley     6 4.164584e-05
2   1908     M Hadley    16 9.616887e-05
3   1909     M Hadley    14 7.915552e-05
4   1910     M Hadley     5 2.397783e-05
5   1911     M Hadley     9 3.728375e-05
6   1912     M Hadley    11 2.436566e-05
7   1913     M Hadley    10 1.864830e-05
8   1914     M Hadley    15 2.195171e-05
9   1915     M Hadley    14 1.589197e-05
10  1916     M Hadley    14 1.516359e-05
# ... with 147 more rows
On the graph we can see, that we should merge some observations:
ggplot(hadley, aes(year, n)) + geom_line()
I have tried aggregate function, but obviously it doesn't work because of categorical variables.
d <- aggregate(x = hadley,by = list(hadley$year),'sum')
How can I correct the code?
 
    