Readable charts need explicit labels for axes and titles.

Program

Play the script to choose which plot label is assembled.

axis_index
axis_labels.R
Replay: real traced execution (multi-file project)
axis_index <- 1
axis <- c("x", "y", "title")[axis_index]
text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]
label <- paste(axis, text, sep = "=")
cat(label, "\n", sep = "")
axis_index <- 2
axis <- c("x", "y", "title")[axis_index]
text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]
label <- paste(axis, text, sep = "=")
cat(label, "\n", sep = "")
axis_index <- 3
axis <- c("x", "y", "title")[axis_index]
text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]
label <- paste(axis, text, sep = "=")
cat(label, "\n", sep = "")
  1. axis_index ← 1

    1axis_index <- 12axis <- c("x", "y", "title")[axis_index]
    values this step1axis_index
  2. axis ← x

    1axis_index <- 12axis <- c("x", "y", "title")[axis_index]3text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]
    values this stepxaxis1axis_index
  3. text ← Month

    2axis <- c("x", "y", "title")[axis_index]3text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]4label <- paste(axis, text, sep = "=")
    values this stepMonthtextxaxis
  4. label ← x=Month

    3text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]4label <- paste(axis, text, sep = "=")5cat(label, "\n", sep = "")
    values this stepx=MonthlabelxaxisMonthtext
  5. cat(label, " ", sep = "")

    4label <- paste(axis, text, sep = "=")5cat(label, "\n", sep = "")
    outputx=Month
    values this stepx=Monthlabel
  1. axis_index ← 2

    1axis_index <- 22axis <- c("x", "y", "title")[axis_index]
    values this step2axis_index
  2. axis ← y

    1axis_index <- 22axis <- c("x", "y", "title")[axis_index]3text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]
    values this stepyaxis2axis_index
  3. text ← Count

    2axis <- c("x", "y", "title")[axis_index]3text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]4label <- paste(axis, text, sep = "=")
    values this stepCounttextyaxis
  4. label ← y=Count

    3text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]4label <- paste(axis, text, sep = "=")5cat(label, "\n", sep = "")
    values this stepy=CountlabelyaxisCounttext
  5. cat(label, " ", sep = "")

    4label <- paste(axis, text, sep = "=")5cat(label, "\n", sep = "")
    outputy=Count
    values this stepy=Countlabel
  1. axis_index ← 3

    1axis_index <- 32axis <- c("x", "y", "title")[axis_index]
    values this step3axis_index
  2. axis ← title

    1axis_index <- 32axis <- c("x", "y", "title")[axis_index]3text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]
    values this steptitleaxis3axis_index
  3. text ← Monthly Count

    2axis <- c("x", "y", "title")[axis_index]3text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]4label <- paste(axis, text, sep = "=")
    values this stepMonthly Counttexttitleaxis
  4. label ← title=Monthly Count

    3text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]4label <- paste(axis, text, sep = "=")5cat(label, "\n", sep = "")
    values this steptitle=Monthly CountlabeltitleaxisMonthly Counttext
  5. cat(label, " ", sep = "")

    4label <- paste(axis, text, sep = "=")5cat(label, "\n", sep = "")
    outputtitle=Monthly Count
    values this steptitle=Monthly Countlabel
axis role A short key can represent the x-axis, y-axis, or chart title.
named text Named vectors let code retrieve the matching display text.
label string The final string is what a plotting call would pass as metadata.