# NOT RUN {
d <-
tibble::data_frame(
day = sample(c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday"),
100, TRUE),
person = sample(c("Tom", "Jane", "Alex"), 100, TRUE),
count = rbinom(100, 20, ifelse(day == "Friday", .5, .2)),
date = Sys.Date() - sample.int(100))
# Minimal arguments are the data and the column to put on the y-axis.
# If x is not provided, observations will be plotted in order of the rows
control_chart(d, "count")
# Specify categorical variables for group1 and/or group2 to get a separate
# panel for each category
control_chart(d, "count", group1 = "day", group2 = "person")
# In addition to printing or writing the plot to file, control_chart
# returns the plot as a ggplot2 obejct, which you can then further customize
library(ggplot2)
my_chart <- control_chart(d, "count", "date")
my_chart +
ylab("Number of Adverse Events") +
scale_x_date(name = "Week of ... ", date_breaks = "week") +
theme(axis.text.x = element_text(angle = -90, vjust = 0.5, hjust=1))
# }
Run the code above in your browser using DataCamp Workspace