Interactive Plots

The Data

Show the code
ds2 <- read_rds("https://raw.githubusercontent.com/bobbyjy/MyData/main/pinot_orig.rds")
datatable(head(ds2))

Plot 1 (Using ggiraph)

Show the code
gg <- ds2 %>% 
  select(taster_name) %>% 
  group_by(taster_name) %>% 
  summarise(taster_name, reviews = n()) %>% 
  distinct() %>% 
  arrange(reviews) %>% 
  ggplot(aes(reviews,reorder(taster_name,reviews), fill = taster_name))+
  #geom_col()+
  geom_col_interactive(aes(tooltip = taster_name, data_id = taster_name), show.legend = FALSE)+
  scale_fill_viridis_d()+
  labs(title = "Which tasters have tasted the most?")
x <- girafe(ggobj = gg, width_svg = 8, height_svg = 6,
            options = list(
              opts_hover_inv(css = "opacity:0.1;"),
              opts_hover(css= "stroke-width:2;")
            ))
x

Plot 2 (Using Plotly)

Show the code
a<-ds2 %>% 
  ggplot(aes(price,points, text = paste("tasted by: ", taster_name,
                                        "<br>",
                                         "description: ", description), color = points))+
  geom_point(show.legend = FALSE)+
  theme_bw()+
  labs(title = "Wine Price vs. Rating", x = "Rating", y = "Price")
ggp <- ggplotly(a)
ggp %>% layout(hovermode = "closest")