jazznbass / scan

Development version of scan: Single-Case Data Analyses for Single and Multiple Baseline Designs
https://jazznbass.github.io/scan/.
GNU General Public License v3.0
3 stars 2 forks source link

new plot function with pipes #43

Closed jazznbass closed 3 years ago

jazznbass commented 3 years ago

Our plot function is becoming more and more bloated. I have redesigned a new approach which embraces a pipe structure and more straight forward functional programming (similar to ggplot). While keeping the previous plot function intact, i like to add it to v0.54 and gradually shift it to be the main approach. Here is an example of what it looks like:

scplot(exampleABAB) %>% 
  add_line("trendA", col = "red") %>%
  add_line("maxA", col = "lightblue") %>%
  add_marks(outlier(exampleABAB), col = "brown", cex = 2) %>%
  set_xaxis(increase = 4, label = "Weeks") %>%
  set_yaxis(lim = c(0, 50), label = "Points") %>%
  add_title("Points as a function of weeks") %>%
  set_case_names("MY", "FUNNY", "VALENTINE") %>%
  set_phase_names("Baseline", "Intervention", "Fall-Back", "Intervention") %>%
  add_style("grid2") %>%
  add_style("tiny") %>%
  add_style(fill.bg = "grey96")

image

beside the clear coding here are some more advantages:

Here is what the code for the above plot would look like with the current function:

plot(exampleABAB, 
     style = list(style = c("grid2", "tiny"), fill.bg = "grey96"),
     lines = list(list("trendA", col = "red"), list("maxA", col = "lightblue")),
     marks = list(positions = outlier(exampleABAB)$dropped.mt, col = "brown", cex = 2),
     xinc = 4, xlab = "Weeks",
     ylim = c(0,50), ylab = "Points",
     main = "Points as a function of weeks",
     case.names = c("MY", "FUNNY", "VALENTINE"),
     phase.names = c("Baseline", "Intervention", "Fall-Back", "Intervention") 
)

@researchtool What do you think?

researchtool commented 3 years ago

Oh I love that! I have a few ideas for plot.scdf() too. That would harmonize with the new approach.

jazznbass commented 3 years ago

I've been adding some more functions and extended the customisability. Here is a current example (a bit extensive to show the possibilities). Any suggestions are welcome :-)

scplot(exampleABAB) %>% 
  add_line("trendA", col = "red") %>%
  add_line("maxA", col = "lightblue") %>%
  add_marks(case = 1, positions = 14, col = "red", cex = 3, pch = 4) %>%
  add_marks(case = 2, positions = c(17, 20), col = "red", cex = 3, pch = 4) %>%
  add_marks(positions = outlier(exampleABAB), col = "brown", cex = 2) %>%
  set_xaxis(increase = 4, label = "Weeks", cex = 0.7, col = "brown") %>%
  set_yaxis(lim = c(0, 50), label = "Points", col = "sienna3", cex = 1, orientation = 0) %>%
  add_title("Points by week", col = "salmon3", cex = 1.5, font = 3) %>%
  set_phasenames("Baseline", "Intervention", "Fall-Back", "Intervention",  cex = 1, col = "darkgreen") %>%
  set_style("grid2") %>%
  set_style("tiny") %>%
  set_style(fill.bg = "grey96") %>%
  add_text(case = 1, 5, 35, "Wow!!", col = "red") %>%
  add_arrow(case = 1, 5, 30, 5, 22, col = "blue") %>%
  set_casenames("MY", "FUNNY", "VALENTINE", col = "darkblue", cex = 0.6)

grafik

jazznbass commented 3 years ago

Meanwhile I started a new package scplot which is intended to be included into scan in a later Version. scplot generated ggplot2 output and thus is extremely versatile