Skip to content

Commit

Permalink
Format R code of plotting function
Browse files Browse the repository at this point in the history
  • Loading branch information
milanwiedemann committed Sep 25, 2024
1 parent b5e1c83 commit 7b20586
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions lib/functions/function_plot_measures.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#' Plot Measures Over Time
#'
#'
#' Creates a line plot of measures over time, with customisable labels and colours.
#'
#'
#' @param data A dataframe containing the data to plot.
#' @param measure_names Strings specifiying the names of measure columns to be plotted.
#' @param custom_labels Strings specifying the names of legend labels.
#' @param title A string specifying the title of the plot. Default is NULL.
#' @param custom_labels Strings specifying the names of legend labels.
#' @param title A string specifying the title of the plot. Default is NULL.
#' @param x_label A string specifying the label for the x-axis. Default is NULL.
#' @param y_label A string specifying the label for the y-axis. Default is NULL.
#' @param y_label A string specifying the label for the y-axis. Default is NULL.
#' @param color_label A string specifying the label for the color legend. Default is NULL.
#' @param value_col The name of the dataframe column which contains the y-axis values. Default is "numerator".
#' @param measure_col The name of the dataframe column which contains the categorical variable. Default is "measure".
#'
#'
#'
#' @return A ggplot object.

# Define the function
plot_measures <- function(
data,
measure_names,
Expand All @@ -28,7 +26,6 @@ plot_measures <- function(
y_label = NULL,
color_label = NULL,
axis_x_text_size = 7) {

# Check if the necessary columns exist in the data
if (date_col %in% names(data) == FALSE) {
stop("Data does not have a column with the name '", date_col, "'")
Expand Down Expand Up @@ -80,24 +77,27 @@ plot_measures <- function(
limits = c(0, NA),
) +
theme_minimal() +
theme(axis.text.x = element_text(size = axis_x_text_size),
legend.position="bottom",
legend.key.size = unit(0.5, "cm"),
legend.text = element_text(size = 8),
legend.title = element_text(size = 8)) +
theme(
axis.text.x = element_text(size = axis_x_text_size),
legend.position = "bottom",
legend.key.size = unit(0.5, "cm"),
legend.text = element_text(size = 8),
legend.title = element_text(size = 8)
) +
# Adjust number of rows in the legend
guides(
color = guide_legend(nrow = 2) # Adjust number of rows in the legend
) +
color = guide_legend(nrow = 2)
) +
geom_vline(
xintercept = lubridate::as_date("2024-02-01"),
linetype = "dotted",
colour = "orange",
linewidth = .7) +
linewidth = .7
) +
scale_x_date(
date_breaks = "1 month",
date_breaks = "1 month",
date_labels = "%b %Y"
)


plot1
}
}

0 comments on commit 7b20586

Please sign in to comment.