diff --git a/lib/functions/function_plot_measures.R b/lib/functions/function_plot_measures.R new file mode 100644 index 0000000..01bec02 --- /dev/null +++ b/lib/functions/function_plot_measures.R @@ -0,0 +1,31 @@ +plot_measures <- function( + data, + title = NULL, + x_label = NULL, + y_label = NULL) { + + # Create plot + plot <- ggplot( + data, + aes( + x = interval_end, + y = numerator, + color = measure, + group = measure + ) + ) + + geom_line() + + labs( + title = title, + x = x_label, + y = y_label, + color = "Condition" + ) + + # Setting the minimum y-value + ylim(y_min, NA) + + # Applying the minimal theme + theme_minimal() + + # Return plot + plot +} diff --git a/lib/functions/graph_func.R b/lib/functions/graph_func.R deleted file mode 100644 index e12a73d..0000000 --- a/lib/functions/graph_func.R +++ /dev/null @@ -1,18 +0,0 @@ -plot_pharmacy_first_conditions <- function(data, -title = "Number of Consultations for each Pharmacy First Clinical Condition per month", - x_label = "Date", - y_label = "Number of Consultations", - y_min = 0) { - ggplot(data, - aes(x = interval_end, - y = numerator, - color = measure, - group = measure)) + - geom_line() + - labs(title = title, - x = x_label, - y = y_label, - color = "Condition") + - ylim(y_min, NA) + # Setting the minimum y-value - theme_minimal() # Applying the minimal theme -} diff --git a/lib/functions/visualise_data.R b/lib/functions/sketch.R similarity index 51% rename from lib/functions/visualise_data.R rename to lib/functions/sketch.R index 2d0b2fe..d4a3725 100644 --- a/lib/functions/visualise_data.R +++ b/lib/functions/sketch.R @@ -1,20 +1,23 @@ +# In this file we're trying out some code library(tidyverse) library(ggplot2) -library(gridExtra) # For arranging multiple plots +library(gridExtra) # For arranging multiple plots # Load data df_measures <- readr::read_csv( here::here("output", "report", "conditions_measures.csv") ) + +# Develop plotting function p <- ggplot(df_measures, aes(x = interval_end, y = numerator, color = measure, group = measure)) + - geom_line() + - labs(title = paste("Number of Consultations for each Pharmacy First Clinical Condition per month"), - x = "Date", - y = "Number of Consultations", - color = "Condition") + - ylim(0, NA) - theme_minimal() - + geom_line() + + labs( + title = paste("Number of Consultations for each Pharmacy First Clinical Condition per month"), + x = "Date", + y = "Number of Consultations", + color = "Condition" + ) + + ylim(0, NA) + source(here::here("lib", "functions", "graph_func.R")) plot1_conditions <- plot_pharmacy_first_conditions(df_measures) - \ No newline at end of file