anhoej / qicharts2

R package: Quality improvement charts
38 stars 12 forks source link

Match line colors to points #23

Closed rjake closed 5 years ago

rjake commented 5 years ago

Would you consider changing the line color to match the points? I like that the excluded points are greyed out and believe that greying out the line helps direct the users eye to focus on non-excluded points. Similarly, I like that the pink points pop more when the line changes color along with it.

image

Here is the code I used

library(tidyverse)
library(qicharts2)

qic_plot <-
  qic(
    data = cdi,
    x = month,
    exclude = c(3, 20),
    y = n,
    chart = "c"
  )

plot_data <- 
  qic_plot$data %>%
  arrange(x, facet1, facet2, part, linecol) %>%
  mutate(
    dotcol =
      recode(dotcol,
        col1 = "grey",
        col2 = "dodgerblue",
        col3 = "deeppink",
        col4 = "green",
        col5 = "grey"
      ),
    next_dotcol = lead(dotcol, default = last(dotcol)),
    prev_dotcol = lag(dotcol, default = first(dotcol)),
    new_linecol =
      case_when(
        next_dotcol == dotcol ~ dotcol,
        next_dotcol == "grey" ~ "grey",
        prev_dotcol == "grey" ~ "grey",
        next_dotcol == "deeppink" ~ "deeppink",
        TRUE ~ dotcol
      )
  )

ggplot(plot_data, aes(x = x, y = y, group = 1)) +
  geom_line(aes(color = new_linecol), size = 1) +
  geom_point(aes(color = dotcol), size = 2) +
  scale_color_identity() +
  theme_minimal()
anhoej commented 5 years ago

Thanks for the idea and well prepared example code. Immediately, I don't think about the idea. I am inspired by the principles suggested by Stephen Few, Edward Tufte and others that warn against "overuse" of colours and other attributes that do not carry data. I agree that your suggestion helps the reader to focus on significant aberrations from the norm and that may justify its use. I'm just not sure this is necessary. But, I'll think about it..