R/plot.start_activities.R

Defines functions plot_start_activities

plot_start_activities <- function(x, ...) {

	mapping <- attr(x, "mapping")
	level <- attr(x, "level")
	absolute <- NULL


	if(level == "log") {
		stop("Plot not available for this level of analysis")
	}
	else if(level == "case") {
		stop("Plot not available for this level of analysis")
	}
	else if(level == "activity") {
		x %>%
			ggplot(aes_string(glue("reorder({mapping$activity_id}, absolute)"), "absolute")) +
			geom_col(aes(fill = absolute)) +
			scale_fill_continuous_tableau(name = "Start Activity Frequency", palette = "Blue")+
			theme_light() +
			coord_flip() +
			labs(x = "Activity", y = "Start Activity Frequency") -> p
	}
	else if(level == "resource") {
		x %>%
			ggplot(aes_string(glue("reorder({mapping$resource_id}, absolute)"), "absolute")) +
			geom_col(aes(fill = absolute)) +
			scale_fill_continuous_tableau(name = "Start Activity Resource Frequency", palette = "Blue")+
			theme_light() +
			coord_flip() +
			labs(x = "Resource", y = "Start Activity Resource Frequency") -> p
	}
	else if(level == "resource-activity") {
		x %>%
			ggplot(aes_string(mapping$resource_id, mapping$activity_id)) +
			geom_tile(aes(fill = absolute)) +
			geom_text(aes(label = absolute), fontface = "bold", color = "white") +
			scale_fill_continuous_tableau(name = "Start Resource-Activity Frequency", palette = "Blue")+
			theme_light() +
			coord_flip() +
			labs(x = "Resource", y = "Activity") +
			theme(axis.text.x = element_text(angle = 45, hjust = 1)) -> p
	}

	if(!is.null(mapping$groups)) {
		p <- p + facet_grid(as.formula(paste(c(paste(mapping$groups, collapse = "+"), "~." ), collapse = "")), scales = "free_y")
	}
	return(p)
}

Try the edeaR package in your browser

Any scripts or data that you put into this service are public.

edeaR documentation built on April 27, 2023, 9:07 a.m.