2024-08-14 12:51:52 +02:00
|
|
|
#!/usr/bin/env Rscript
|
|
|
|
|
|
|
|
# Libraries:
|
|
|
|
library(reshape2)
|
|
|
|
library(tidyverse)
|
|
|
|
|
|
|
|
# Parsing command line arguments:
|
|
|
|
options = commandArgs(trailingOnly = TRUE)
|
2024-08-21 15:33:49 +02:00
|
|
|
plot_type = options[1]
|
|
|
|
input = options[2]
|
|
|
|
output = options[3]
|
|
|
|
table_header = options[-1:-2:-3]
|
2024-08-14 12:51:52 +02:00
|
|
|
|
2024-08-21 15:33:49 +02:00
|
|
|
pdf(output)
|
|
|
|
|
|
|
|
read_csv(input, col_names = table_header) %>%
|
2024-08-14 12:51:52 +02:00
|
|
|
mutate(timestamp = as_date(as_datetime(timestamp))) %>% # Formatting the date
|
|
|
|
melt(id.vars = "timestamp", variable.name = "category", value.name = "amount") %>% # Formatting the table to plot each category
|
|
|
|
{
|
|
|
|
if (plot_type == "bar")
|
|
|
|
ggplot(data = ., aes(x = timestamp, y = amount, fill = category)) + geom_bar(stat = "identity")
|
|
|
|
else if (plot_type == "line")
|
|
|
|
ggplot(data = ., aes(x = timestamp, y = amount)) + geom_line(aes(color = category))
|
|
|
|
}
|