I'm using a facet_wrap combined with a geom_col, but the ordering isn't how I'd like it to appear - below is the graph as it looks now and you can clearly see the ordering in the top section is not correct:
Unfortunately, I've tried several things to fix this, but can't figure it out. Here's the code I'm using for the table as well as the data:
library(tidyverse)
library(dplyr)
library(ggimage)
library(ggrepel)
library(nflfastR)
library(magick)
library(cowplot)
library(showtext)
library(jsonlite)
library(curl)
library(rsvg)
library(ggsci)
library(ggridges)
library(ggthemes)
library(shadowtext)
font_add_google("Encode Sans Condensed", "encode", regular.wt = 400, bold.wt = 600)
font_add_google("Inconsolata", "incon")
showtext_auto()
ggplot(data = arizona,aes(x = pct_team_ep, y = reorder(player_name, rank), fill = Team))+
geom_col(show.legend = FALSE, position = "identity")+
geom_shadowtext(aes(x = pct_team_ep + 0.02, color = Team, label = player_name), typeface = "bold", hjust = 0, bg.color = 'white', family = "incon", size = 3.5, na.rm = T, bg.r = 0.2, show.legend = FALSE) +
scale_x_continuous(labels = scales::percent_format(accuracy=1),
expand = expansion(mult = 0), limits = c(0,1),
name = "",
breaks = scales::pretty_breaks(5)) +
scale_fill_manual(values = NFL_pri) +
scale_color_manual(values = NFL_sec) +
facet_wrap( ~ ep_type, ncol = 1, scales = "free") +
theme_bw()+
theme(
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.ticks.x = element_line(size = 0.5),
strip.background = element_rect(
fill= "white", size=1, linetype="solid"),
strip.text.x = element_text(
size = 12, color = arizona$team_color, family = "encode", face = "bold"
))
Team | player_name | team_color | ep_type | pct_team_ep | rank |
---|---|---|---|---|---|
TB | B. Gabbert | #d50a0a | % Team Rushing Expected Fantasy Points | 0.05803571 | 4 |
TB | C. Godwin | #d50a0a | % Team Receiving Expected Fantasy Points | 0.22020287 | 14 |
TB | J. Watson | #d50a0a | % Team Receiving Expected Fantasy Points | 0.05592323 | 3 |
TB | K. Vaughn | #d50a0a | % Team Receiving Expected Fantasy Points | 0.05365854 | 2 |
TB | K. Vaughn | #d50a0a | % Team Rushing Expected Fantasy Points | 0.11612903 | 9 |
TB | L. Fournette | #d50a0a | % Team Receiving Expected Fantasy Points | 0.07182683 | 6 |
TB | L. Fournette | #d50a0a | % Team Rushing Expected Fantasy Points | 0.31750339 | 15 |
TB | L. McCoy | #d50a0a | % Team Receiving Expected Fantasy Points | 0.06256446 | 5 |
TB | M. Evans | #d50a0a | % Team Receiving Expected Fantasy Points | 0.16322217 | 13 |
TB | O. Howard | #d50a0a | % Team Receiving Expected Fantasy Points | 0.12724307 | 11 |
TB | R. Gronkowski | #d50a0a | % Team Receiving Expected Fantasy Points | 0.15147957 | 12 |
TB | R. Jones | #d50a0a | % Team Receiving Expected Fantasy Points | 0.09816815 | 7 |
TB | R. Jones | #d50a0a | % Team Rushing Expected Fantasy Points | 0.57880435 | 16 |
TB | S. Miller | #d50a0a | % Team Receiving Expected Fantasy Points | 0.11648661 | 10 |
TB | T. Brady | #d50a0a | % Team Rushing Expected Fantasy Points | 0.11413043 | 8 |
TB | T. Johnson | #d50a0a | % Team Receiving Expected Fantasy Points | 0.05351488 | 1 |
Any suggestions on what to do? Let me know and thanks in advance!