I'm building an NBA R Shiny Application and I'm running into a small problem trying to make interactive plots. My Geom smooth element works in the first set of code I've provided which shows a smoothing average of the margin of victory for the selected team, but once I implement custom tooltips with ggplotly the geom smooth element stops working.
mov_plot <- function(df){
p <- df %>%
ggplot(aes(Date, Margin_of_Victory)) +
geom_col(color = 'black', alpha = 0.7, aes(fill = Outcome)) +
geom_smooth(method = 'loess', se = FALSE, color = 'grey20', alpha = 0.4) +
scale_y_continuous(breaks = c(-25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25)) +
scale_fill_manual(values = c("red", "dark green")) +
labs(x = NULL,
y = 'Margin of Victory',
title = paste0(df$FullName, ' Game Log History \n 2019-2020 NBA Season'),
subtitle = '2019-2020 NBA Season') +
theme_jacob()
ggplotly(p)
}
mov_plot <- function(df){
p <- df %>%
ggplot(aes(Date, Margin_of_Victory, text = paste(Date, '<br>',
Outcome, ' vs', Opponent, '<br>',
'Scoreline: ', team_pts, ' - ', Opp_PTS, '<br>',
'Margin of Victory: ', Margin_of_Victory))) +
geom_col(color = 'black', alpha = 0.7, aes(fill = Outcome)) +
geom_smooth(method = 'loess', se = FALSE, color = 'grey20', alpha = 0.4) +
scale_y_continuous(breaks = c(-25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25)) +
scale_fill_manual(values = c("red", "dark green")) +
labs(x = NULL,
y = 'Margin of Victory',
title = paste0(df$FullName, ' Game Log History \n 2019-2020 NBA Season'),
subtitle = '2019-2020 NBA Season') +
theme_jacob()
ggplotly(p, tooltip = c('text'))
}
Below are 2 images showing the problem where the geom_smooth element just disappears when I use the second set of code.
If anyone has experience with plotly and has any ideas on a potential fix I'd greatly appreciate it !