I'm plotting a dataset of shot locations on an ice rink. I want to use plotly
to enable users to see a description box once they hover over each point. I thought this would be done using the custom tooltip
The ice rink is stored in a rink
object.
rink <- rasterGrob(readJPEG("full-rink.jpg"))
Here is full-rink.jpg
This is the first 5 rows of the dataset I'm working with:
structure(list(game_date = structure(c(17674, 17674, 17674, 17674,
17674), class = "Date"), event_team = c("WSH", "WSH", "T.B",
"T.B", "T.B"), event_description = c("WSH #8 OVECHKIN(12), Slap, Off. Zone, 53 ft.Assists: #92 KUZNETSOV(13); #43 WILSON(8) Expected Goal Prob: 1.6%",
"WSH ONGOAL - #92 KUZNETSOV, Wrist, Off. Zone, 13 ft. Expected Goal Prob: 50.4%",
"T.B ONGOAL - #17 KILLORN, Backhand, Off. Zone, 18 ft. Expected Goal Prob: 4.5%",
"T.B ONGOAL - #17 KILLORN, Wrist, Off. Zone, 23 ft. Expected Goal Prob: 4.6%",
"T.B ONGOAL - #27 MCDONAGH, Slap, Off. Zone, 57 ft. Expected Goal Prob: 1.2%"
), event_type = c("GOAL", "SHOT", "SHOT", "SHOT", "SHOT"), home_team = c("T.B",
"T.B", "T.B", "T.B", "T.B"), away_team = c("WSH", "WSH", "WSH",
"WSH", "WSH"), coords_x = c(-42, -80.3, 71, 67, 34), coords_y = c(-21,
12, -3, 9, 19)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-5L))
Here is the code for my plot:
example_data %>%
ggplot(aes(coords_x, coords_y, text = event_description)) +
annotation_custom(rink, -100, 100, -45, 45) +
geom_point(aes(color = event_team), size = 3, show.legend = FALSE) +
coord_fixed() +
xlim(-100, 100) +
ylim(-45, 45) +
theme_nothing() +
theme(text = element_text(size = 15),
plot.title = element_text(hjust = 0.5)) +
ggtitle(paste0(game_date, "\n", away_team, " vs ", home_team)) +
scale_color_manual(values = c("#000000", "slategrey"))
Unfortunately, once I run
ggplotly(pbp_plotly_processed)
, I get an error message:
Warning message:
In geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]) :
geom_GeomCustomAnn() has yet to be implemented in plotly.`
Don't think this is possible in plotly
yet. Is there a workaround that anyone can suggest?
Thank you!