Visits by browser

browser_plot <- browser %>%
  mutate(device = if_else(is_mobile == TRUE, "Mobile", "Desktop")) %>%
  group_by(browser, device) %>%
  summarise(visits = n(), .groups = "drop")

browser_order <- browser_plot %>%
  group_by(browser) %>%
  summarise(total_visits = sum(visits)) %>%
  arrange(total_visits) %>%
  pull(browser)

browser_plot$browser <- factor(browser_plot$browser, levels = browser_order)

ggplotly(
  ggplot(browser_plot, aes(x = browser, y = visits, fill = device)) +
    geom_col(
      position = position_dodge2(width = 0.7, preserve = "single", reverse = TRUE),
      width = 0.6
    ) +
    labs(
      title = "Visits by Browser and Device Type",
      x = "Browser",
      y = "Number of visits",
      fill = "Device"
    ) +
    scale_fill_manual(
      values = c(
        "Mobile" = "#CD5C5C",
        "Desktop" = "#800080"  
      )
    ) +
    theme_minimal(base_size = 14)
)