Visualization starts by choosing the series that should become the plotted values.

Program

Play the script to change the selected metric and watch the plotted-series summary update.

chart_series.R
metric_index <- 
metric <- c("visits", "orders", "revenue")[metric_index]
series <- list(visits = c(12, 18, 21), orders = c(3, 5, 6), revenue = c(30, 52, 61))[[metric]]
total <- sum(series)
label <- paste(metric, total, sep = ":")
cat(label, "\n", sep = "")
metric_index <- 
metric <- c("visits", "orders", "revenue")[metric_index]
series <- list(visits = c(12, 18, 21), orders = c(3, 5, 6), revenue = c(30, 52, 61))[[metric]]
total <- sum(series)
label <- paste(metric, total, sep = ":")
cat(label, "\n", sep = "")
metric_index <- 
metric <- c("visits", "orders", "revenue")[metric_index]
series <- list(visits = c(12, 18, 21), orders = c(3, 5, 6), revenue = c(30, 52, 61))[[metric]]
total <- sum(series)
label <- paste(metric, total, sep = ":")
cat(label, "\n", sep = "")
metric choice A selected name chooses one vector from a named list.
series The selected vector is the data a plotting call would draw.
summary label A small label confirms which series is being prepared.