0

I would like to make Whole face_wrap graphs with min and max values coloured. But when I ran the code below it only colour the min/max for all graph not individually.

ggplot(data = df, aes(
  x = factor(day_of_week,
    levels =
      c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
  ),
  y = total_total_intensity
)) +
  geom_bar(stat = "sum") +
  geom_bar(
    data = subset(df, total_total_intensity == min(total_total_intensity)),
    aes(day_of_week, total_total_intensity),
    fill = "red", stat = "sum"
  ) +
  geom_bar(
    data = subset(df, total_total_intensity == max(total_total_intensity)),
    aes(day_of_week, total_total_intensity),
    fill = "green", stat = "sum"
  ) +
  facet_wrap(~time_of_day) +
  theme(axis.text.x = element_text(angle = 45)) +
  labs(
    title = "Daily Activity Per Daytime", x = "Day of the week",
    y = "Total Intensity", subtitle = "Whole week"
  )

How can I highlight the min/max individually for this code?

graphs

stefan
  • 90,330
  • 6
  • 25
  • 51
  • 3
    Try with e.g. `data = dplyr::slice_min(df, total_total_intensity, n = 1, by = time_of_day)` for the min values. This will give you a dataset with the mins by time_of_day. And `dplyr::slice_max` for the max. For more help please provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Jul 28 '23 at 13:51

0 Answers0