Ascending and Descending order for a continuous variable

Still new to R Studio and ggplot2 so forgive my newbieness, but I have a simple geom_col visualization of total goals scored by each NHL team in a given season and I would like to re-order them in either ascending or descending order. I've looked all over, tried arrange(), order(), etc. but am still struggling. Any help would be greatly appreciated!

game_goals_NHL %>%
filter(season == 2012) %>%
ggplot() +
theme(panel.grid.minor = element_blank(),
panel.background = element_rect(fill = "light blue"),
panel.grid.major.y = element_blank(),
text = element_text(family = "serif"),
aspect.ratio = .5) +
scale_x_continuous(limits = c(0, 100), expand = c(0.005, 0.005)) +
labs(title = "NHL Goals by Team, 2009",
subtitle = "San Jose had the most goals but didn't with the Stanley Cup",
caption = "viz by Rich with ggplot") +
aes(x = goals, y = team) +
geom_col(alpha = .6)

You can use the reorder function as shown below.

library(ggplot2)
set.seed(1)
DF <- data.frame(Team = LETTERS[1:15], Goals = sample(1:15))
ggplot(DF, aes(Team, Goals)) + geom_col()

ggplot(DF, aes(reorder(Team, Goals), Goals)) + geom_col()

Created on 2020-05-04 by the reprex package (v0.3.0)

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