I am trying to make this geom_bar plot into a geom_line graph but I do not know how to use summarize and n()

prem_league_stats <- read_excel("../Final-project/prem_league_stats.xlsx")

#| echo: false
#| message: false
#| warning: false
prem_league_stats|>
  select(part_of_body, injury, goals_overall, position, `Current Club`, age, full_name)|>
  drop_na(part_of_body, injury)|>
  ggplot(mapping = aes(x = age)) +
  geom_bar() +
  labs(title = "Total Soccer Injuries Related to Age ",
       x = "Age",
       y = "Total number of Injuries")

I can't test this without your data, but try this:

prem_league_stats|>
    drop_na(part_of_body, injury)|>
    group_by(age) |>
    summarize(N = n()) |>
  ggplot(mapping = aes(x = age, y = N)) +
  geom_line() +
  labs(title = "Total Soccer Injuries Related to Age ",
       x = "Age",
       y = "Total number of Injuries")

This topic was automatically closed 21 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.