1

I am trying to make a visualization to show the rankings of different football teams on metrics where the highest possible values is 1 and the lowest is 130 (the number of college football teams). How would I make the Y axis so that the bars show low values as high bars?

df %>%
   filter(Team == "Air Force (Mountain West)") %>% 
   pivot_longer(cols = c(`Off Rank`, 
                    `First Down Rank`, 
                    `4th Down Rank`, 
                    `Redzone Off Rank`, 
                    `Rushing Off Rank`, 
                    `Scoring Off Rank`, 
                    `3rd Down Rank`, 
                    `Time of Possession Rank`),
           names_to = "Ranks",
           values_to = "Values"
           ) %>% 
   ggplot(aes(x = Ranks, y = Values, fill = Values)) +
   geom_col() +
   coord_polar()

Caveat: I have though about taking the values and subtracting them from 130 to flip them, but I might one to show the rankings as values also. Thank you.

Jeff Gallini
  • 35
  • 2
  • 5
  • Can you provide a reproducible example of your dataset ? see here: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – dc37 Jan 30 '20 at 17:41

1 Answers1

1

It's a bit weird, but you need to transform your values, such that rank 1 is the highest and you change your y-axis ticks accordingly. If you provide your dataset, we can try it, but below should get you going:

set.seed(100)

df = data.frame(Ranks=letters[1:20],Values=sample(20))
# define the breaks for your ranks
BR = round(seq(min(df$Values),max(df$Values),length.out=5))
g = df %>% 
mutate(Var=max(Values)-Values+1) %>% 
ggplot(aes(x=Ranks,y=Var,fill=Var)) + geom_col() + ylab("Rank")+
scale_y_continuous(breaks=BR,labels=rev(BR))

Looks like this:

enter image description here

And when you convert to polar.. Not so sure about the y-axis but I guess it has the intended effect:

 g+coord_polar() 

enter image description here

StupidWolf
  • 45,075
  • 17
  • 40
  • 72