Closed philly1993 closed 4 months ago
Hi, sorry for the delay in responding here. Working on this a bit... can you provide me with what tmp
contains so I can try to recreate what it is you're doing?
Actually, was able to simulate your data a bit. The code below works, although you may need to adjust the positional parameters for annotation_custom()
library(sportyR)
library(ggplot2)
library(grid)
library(png)
set.seed(2379)
tmp <- data.frame(
manpowerSituation = sample(
c("EV", "PP"),
size = 100,
replace = TRUE,
prob = c(.5, .5)
),
x = runif(100, -22, 22),
y = runif(100, 65, 88),
shotResult = sample(
c("goal", "onnet", "missed"),
size = 100,
replace = TRUE,
prob = c(1/3, 1/3, 1/3)
)
)
# Note that this will need to be changed based on your file name/location
wsh <- grid::rasterGrob(png::readPNG("wsh.png"))
geom_hockey(league = "NHL", rotation = 90, display_range = "ozone") +
geom_point(data = tmp, aes(x = x, y = y), color = "navy", alpha = 0.5, size = 1) +
annotation_custom(wsh, xmin = -11, xmax = 11, ymin = 92, ymax = 100) +
facet_grid(~manpowerSituation~shotResult) +
NULL
Also noting here you can use geom_image()
if you add the image to the data:
library(sportyR)
library(ggplot2)
library(grid)
library(png)
set.seed(2379)
tmp <- data.frame(
manpowerSituation = sample(
c("EV", "PP"),
size = 100,
replace = TRUE,
prob = c(.5, .5)
),
x = runif(100, -22, 22),
y = runif(100, 65, 88),
shotResult = sample(
c("goal", "onnet", "missed"),
size = 100,
replace = TRUE,
prob = c(1/3, 1/3, 1/3)
)
)
tmp$image <- here::here("wsh.png")
geom_hockey(league = "NHL", rotation = 90, display_range = "ozone") +
geom_point(data = tmp, aes(x = x, y = y), color = "navy", alpha = 0.5, size = 1) +
geom_image(data = tmp, aes(x = 0, y = 96, image = image), size = 0.1, by = "width") +
facet_grid(~manpowerSituation~shotResult)
@philly1993 just confirming that this resolves the problem? If so (or after ~a week of inactivity here), I'm going to close this issue
Closing due to inactivity; feel free to open a new issue if more support needed
I am trying to add a logo to a rink using
ggimage::geom_image
and afacet_grid
but I am getting an error. I am able to add the logo without adding the facet_grid and use the facet_grid without the logo, but not both. Any advice will be appreciated. Thanks!Example:
This errors out
These two work