-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplot_functions.R
More file actions
31 lines (28 loc) · 1.1 KB
/
Copy pathplot_functions.R
File metadata and controls
31 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
################################################################################
#' Plot chart function
#'
#' This function plots the control chart
#'
#' @param plot_data a dataframe object
#' @param plot_type type of plot
#' @param var_name variable name
#' @importFrom ggplot2 ggplot geom_line geom_point labs
#' @return a ggplot object (plot)
#'
#' @export
#'
plot_chart <- function(plot_data, plot_type, var_name)
{
# Plot the chart
pl <- ggplot(plot_data, aes(x, data_points)) + geom_point(colour = "green", size = 6)
pl <- pl +
geom_line(aes(x, data_points, colour = "Data points trace"), data = plot_data) +
geom_line(aes(x, center, colour = "Center"), data = plot_data, lwd = 2) +
geom_line(aes(x, lcl, colour = "LCL"), data = plot_data, lwd = 2) +
geom_line(aes(x, ucl, colour = "UCL"), data = plot_data, lwd = 2) +
# Add legend
scale_colour_manual(values = c("navyblue", "blue", "red", "red")) +
# Add labels and title
labs(title = paste("Control chart displayed:", plot_type) ,x = "Group", y = var_name)
return(pl)
}