Visualization Workflows
Axis Labels
Build Plot Text
Readable charts need explicit labels for axes and titles.
Program
Play the script to choose which plot label is assembled.
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 = "")
axis_index ← 1
1axis_index <- 12axis <- c("x", "y", "title")[axis_index]values this step1axis_indexaxis ← x
1axis_index <- 12axis <- c("x", "y", "title")[axis_index]3text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]values this stepxaxis1axis_indextext ← 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 stepMonthtextxaxislabel ← x=Month
3text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]4label <- paste(axis, text, sep = "=")5cat(label, "\n", sep = "")values this stepx=MonthlabelxaxisMonthtextcat(label, " ", sep = "")
4label <- paste(axis, text, sep = "=")5cat(label, "\n", sep = "")outputx=Monthvalues this stepx=Monthlabel
axis_index ← 2
1axis_index <- 22axis <- c("x", "y", "title")[axis_index]values this step2axis_indexaxis ← y
1axis_index <- 22axis <- c("x", "y", "title")[axis_index]3text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]values this stepyaxis2axis_indextext ← 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 stepCounttextyaxislabel ← y=Count
3text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]4label <- paste(axis, text, sep = "=")5cat(label, "\n", sep = "")values this stepy=CountlabelyaxisCounttextcat(label, " ", sep = "")
4label <- paste(axis, text, sep = "=")5cat(label, "\n", sep = "")outputy=Countvalues this stepy=Countlabel
axis_index ← 3
1axis_index <- 32axis <- c("x", "y", "title")[axis_index]values this step3axis_indexaxis ← title
1axis_index <- 32axis <- c("x", "y", "title")[axis_index]3text <- c(x = "Month", y = "Count", title = "Monthly Count")[[axis]]values this steptitleaxis3axis_indextext ← 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 Counttexttitleaxislabel ← 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 Counttextcat(label, " ", sep = "")
4label <- paste(axis, text, sep = "=")5cat(label, "\n", sep = "")outputtitle=Monthly Countvalues 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.