I have a spreadsheet that shows the ages and games played for baseball players.
structure(list(Player = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18), Games = c(21, 7, 159, 156, 10, 152,
23, 68, 13, 123, 29, 13, 111, 2, 84, 15, 140, 93), Age = c(34,
23, 33, 22, 28, 24, 28, 33, 33, 29, 29, 25, 20, 41, 37, 21, 22,
31), under21 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
0, 0, 0), Y21to25 = c(0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0,
0, 0, 1, 1, 0), Y26to30 = c(0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1,
0, 0, 0, 0, 0, 0, 0), Y31to35 = c(1, 0, 1, 0, 0, 0, 0, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 1), Y36to40 = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0), over40 = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)), row.names = c(NA, 18L), class = "data.frame")
Here is another view of it using glimpse(df). I added the six columns from "under21" thru "over40" for illustrative purposes.
Observations: 18
Variables: 9
$ Player <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18
$ Games <dbl> 21, 7, 159, 156, 10, 152, 23, 68, 13, 123, 29, 13, 111, 2, 84…
$ Age <dbl> 34, 23, 33, 22, 28, 24, 28, 33, 33, 29, 29, 25, 20, 41, 37, 2…
$ under21 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0
$ Y21to25 <dbl> 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0
$ Y26to30 <dbl> 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0
$ Y31to35 <dbl> 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1
$ Y36to40 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0
$ over40 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0
What I need is a bar chart with six bars ("under21" thru "over40") rising from the x-axis. The y-axis, "Games," will show the number of games played by all the players in each age group. So, the "under21" bar will show the total games played by all the players under age 21, and so on.
What is the best way to do that?

