Missing element_nfl_logo when changing scale position
Closed this issue · 2 comments
Adeiko commented
Hi!
Maybe I'm doing something wrong, but I can't seem to be able to replace team names for logos when you move the X axis to the top with nflplotR::element_nfl_logo
This is some small example:
example <- data.frame(
week = c(1, 2, 3),
tm_opp_team = c("KC", "LV", "LA"),
snap_total = c(47, 18, 50)
)
ggplot2::ggplot(example,aes(x=tm_opp_team,y=snap_total,))+
geom_point()+
ggplot2::scale_x_discrete(position="top")+
ggplot2::theme(axis.text.x = nflplotR::element_nfl_logo())
If you let the X on the bottom or remove the nfl_logo element they show up correctly
ggplot2::ggplot(example,aes(x=tm_opp_team,y=snap_total,))+
geom_point()+
ggplot2::scale_x_discrete()+
ggplot2::theme(axis.text.x = nflplotR::element_nfl_logo())
ggplot2::ggplot(example,aes(x=tm_opp_team,y=snap_total,))+
geom_point()+
ggplot2::scale_x_discrete(position="top")
This was the nflplotR version I used:
> nflverse::nflverse_sitrep("nflplotR")
── System Info ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• R version 4.2.1 (2022-06-23 ucrt) • Running under: Windows 10 x64 (build 19043)
── nflverse Packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• nflplotR (1.1.0)
── nflverse Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
No options set for nflplotR
── nflverse Dependencies ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• cachem (1.0.6) • labeling (0.4.2) • pkgconfig (2.0.3)
• cli (3.4.1) • lattice (0.20-45) • R6 (2.5.1)
• colorspace (2.0-3) • lifecycle (1.0.2) • rappdirs (0.3.3)
• curl (4.3.2) • magick (2.7.3) • RColorBrewer (1.1-3)
• data.table (1.14.2) • magrittr (2.0.3) • Rcpp (1.0.9)
• digest (0.6.29) • MASS (7.3-58.1) • rlang (1.0.6)
• fansi (1.0.3) • Matrix (1.5-1) • scales (1.2.1)
• farver (2.1.1) • memoise (2.0.1) • tibble (3.1.8)
• fastmap (1.1.0) • mgcv (1.8-40) • utf8 (1.2.2)
• ggplot2 (3.3.6) • munsell (0.5.0) • vctrs (0.4.1)
• glue (1.6.2) • nflreadr (1.3.1) • viridisLite (0.4.1)
• gtable (0.3.1) • nlme (3.1-159) • withr (2.5.0)
• isoband (0.2.5) • pillar (1.8.1)
mrcaseb commented
For some reason - I did not know this until now - axis.text.x does not talk to the top version of the axis.
Try
library(ggplot2)
example <- data.frame(
week = c(1, 2, 3),
tm_opp_team = c("KC", "LV", "LA"),
snap_total = c(47, 18, 50)
)
ggplot(example,aes(x=tm_opp_team,y=snap_total,))+
geom_point() +
# ggplot2::scale_x_discrete(position="top")+
scale_x_discrete(position = "top")+
theme(
axis.text.x.top = nflplotR::element_nfl_logo()
)
Created on 2022-09-29 with reprex v2.0.2
mrcaseb commented
It is absolutely possible that this has something to do with how I have implemented the theme elements. But since axis.text.x.top
is working fine I will not bother.