#' This simple ggplot function takes the name of an x-axis column and a y-axis column and plots a line chart, with different grouping variables represented as unique factor colors. Function is primarily used to create composite charts while keeping the theme choices consistent.
#' @export
#' @title Grouped line chart for continuous data time series
#' @param dat a dataframe containing your 'x' and 'y' variables of interest
#' @param xcol a character object specifying the column name of the x-axis variable (e.g. doy)
#' @param ycol a character object specifying the column name of the x-axis variable
#' @param group a character object specifying the column name of the grouping variable (e.g. year)
#' @importFrom ggplot2 ggplot aes geom_line theme element_text element_blank element_line
## fPlot_GroupedLine_Single was written to be a simple ggplot function while creating composite plots
# Plots y ~ x using a line chart
fPlot_GroupedLine_Single <- function(dat, xcol, ycol, group) {
# Convert your grouping variable into a factor
dat[[group]] <- factor(dat[[group]])
p <- ggplot(dat, aes(x = .data[[xcol]], y = .data[[ycol]], color = .data[[group]])) +
geom_line(alpha=0.4) +
theme(
plot.title = element_text(color="black", hjust = 0.5, size=13, face="bold"),
plot.subtitle = element_text(color="black", hjust = 0.5, size=11, face="bold"),
axis.line=element_line(size=0.75),
axis.title.x=element_blank(),
axis.text.x=element_text(size=12,color="black"),
axis.title.y=element_text(size=12,color="black"),
axis.text.y=element_text(size=12,color="black"),
panel.background=element_blank(),
legend.position = "none"
)
return(p)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.