Creating a bar chart with multivariate data

Hi, I'm trying to understand how to create a simple bar chart.
My data has 5 columns and 18 rows with the number of goals scored in each round by each team as follows:
Playing_Round,Team1,Team2,Team3,Team4,Team5
1,4,2,5,1,5
2,3,6,1,5,7
3,2,1,2,3,4
4,4,5,2,3,5
..
18,4,8,9,1,2

So I'd like to create a bar chart showing the number of goals each team scored for each round.

I'm guessing this is basic but I cannot figure out how to create it.

I'm happy if pointers are provided rather than answers but I'll take answers too :slight_smile:
Thanks.

Here is an example with four rounds. Eighteen rounds might be rather hard to read.

library(tidyr)
library(ggplot2)
DF <- data.frame(Round = 1:4,
                 Team1 = c(4,3,2,3), Team2 = c(2,6,1,5),
                 Team3 = c(5,1,2,2), Team4 = c(1,5,3,3), Team5 = c(5,7,4,5))
DFlong <- DF %>% pivot_longer(cols = Team1:Team5, names_to = "TEAM", values_to = "Goals")
head(DFlong)
#> # A tibble: 6 x 3
#>   Round TEAM  Goals
#>   <int> <chr> <dbl>
#> 1     1 Team1     4
#> 2     1 Team2     2
#> 3     1 Team3     5
#> 4     1 Team4     1
#> 5     1 Team5     5
#> 6     2 Team1     3
ggplot(DFlong, aes(x = Round, y = Goals, fill = TEAM)) + geom_col(position = "dodge")

Created on 2020-09-19 by the reprex package (v0.3.0)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.