I am fairly new to working in RStudio and have been struggling to create a stacked bar chart. I wanted the the bar chart to stack "shots" and "goals". I'd appreciate any advice.
(I am also trying to create my first reprex. This may not be in the correct format, and I'll take advice on that too!) Thank you.
library(ggplot)
df <- data.frame(stringsAsFactors = FALSE,
team.name = c("Australia", "Brazil", "Canada", "England", "France", "Germany")
shots = c(14.2, 12.8, 15.2, 12.7, 18.2, 15.4)
goals = c(2.25, 1.75, 1, 1.86, 2, 2)
total_combined = c(16.5, 14.5, 16.2, 14.6, 20.2, 17.4)
ggplot(data = shots_goals,
aes(x = reorder(team.name, shots), y = total_combined, fill = "goals")) +
geom_bar(stat = "identity", width = 0.5) +
labs(y="Average Shots Per Game") +
geom_col(fill = "lightblue", , width = 0.5)+
theme(axis.title.y = element_blank()) +
scale_y_continuous( expand = c(0,0)) +
coord_flip() +
theme_SB()