A scatter plot maps paired vectors to horizontal and vertical positions. The plot type controls whether points, lines, or both are drawn.

Program

Play the script to choose the plot type and watch the same x/y data feed a base R plot call.

type_index
scatter_plot_mapping.R
Replay: real traced execution (multi-file project)
x <- c(1, 2, 3, 4)
type_index <- 1
plot_type <- c("p", "l", "b")[type_index]
y <- x * 2
pdf(tempfile(fileext = ".pdf"))
plot(x, y, type = plot_type, main = "Growth")
invisible(dev.off())
summary <- paste(plot_type, tail(y, 1), sep = ":")
cat(summary, "\n", sep = "")
x <- c(1, 2, 3, 4)
type_index <- 2
plot_type <- c("p", "l", "b")[type_index]
y <- x * 2
pdf(tempfile(fileext = ".pdf"))
plot(x, y, type = plot_type, main = "Growth")
invisible(dev.off())
summary <- paste(plot_type, tail(y, 1), sep = ":")
cat(summary, "\n", sep = "")
x <- c(1, 2, 3, 4)
type_index <- 3
plot_type <- c("p", "l", "b")[type_index]
y <- x * 2
pdf(tempfile(fileext = ".pdf"))
plot(x, y, type = plot_type, main = "Growth")
invisible(dev.off())
summary <- paste(plot_type, tail(y, 1), sep = ":")
cat(summary, "\n", sep = "")
  1. x ← 1, 2, 3, 4

    1x <- c(1, 2, 3, 4)2type_index <- 1
    values this step1, 2, 3, 4x
  2. type_index ← 1

    1x <- c(1, 2, 3, 4)2type_index <- 13plot_type <- c("p", "l", "b")[type_index]
    values this step1type_index
  3. plot_type ← p

    2type_index <- 13plot_type <- c("p", "l", "b")[type_index]4y <- x * 2
    values this steppplot_type1type_index
  4. y ← 2, 4, 6, 8

    3plot_type <- c("p", "l", "b")[type_index]4y <- x * 25pdf(tempfile(fileext = ".pdf"))
    values this step2, 4, 6, 8y1, 2, 3, 4x
  5. graphics device ← temporary PDF device

    4y <- x * 25pdf(tempfile(fileext = ".pdf"))6plot(x, y, type = plot_type, main = "Growth")
    values this steptemporary PDF devicegraphics device
  6. plot ← Growth scatter plot (points)

    5pdf(tempfile(fileext = ".pdf"))6plot(x, y, type = plot_type, main = "Growth")7invisible(dev.off())
    values this stepGrowth scatter plot (points)plot1, 2, 3, 4x2, 4, 6, 8ypplot_type
  7. graphics device ← closed

    6plot(x, y, type = plot_type, main = "Growth")7invisible(dev.off())8summary <- paste(plot_type, tail(y, 1), sep = ":")
    values this steptemporary PDF device closedgraphics device
  8. summary ← p:8

    7invisible(dev.off())8summary <- paste(plot_type, tail(y, 1), sep = ":")9cat(summary, "\n", sep = "")
    values this stepp:8summarypplot_type8tail(y, 1)
  9. cat(summary, " ", sep = "")

    8summary <- paste(plot_type, tail(y, 1), sep = ":")9cat(summary, "\n", sep = "")
    outputp:8
    values this stepp:8summary
  1. x ← 1, 2, 3, 4

    1x <- c(1, 2, 3, 4)2type_index <- 2
    values this step1, 2, 3, 4x
  2. type_index ← 2

    1x <- c(1, 2, 3, 4)2type_index <- 23plot_type <- c("p", "l", "b")[type_index]
    values this step2type_index
  3. plot_type ← l

    2type_index <- 23plot_type <- c("p", "l", "b")[type_index]4y <- x * 2
    values this steplplot_type2type_index
  4. y ← 2, 4, 6, 8

    3plot_type <- c("p", "l", "b")[type_index]4y <- x * 25pdf(tempfile(fileext = ".pdf"))
    values this step2, 4, 6, 8y1, 2, 3, 4x
  5. graphics device ← temporary PDF device

    4y <- x * 25pdf(tempfile(fileext = ".pdf"))6plot(x, y, type = plot_type, main = "Growth")
    values this steptemporary PDF devicegraphics device
  6. plot ← Growth scatter plot (lines)

    5pdf(tempfile(fileext = ".pdf"))6plot(x, y, type = plot_type, main = "Growth")7invisible(dev.off())
    values this stepGrowth scatter plot (lines)plot1, 2, 3, 4x2, 4, 6, 8ylplot_type
  7. graphics device ← closed

    6plot(x, y, type = plot_type, main = "Growth")7invisible(dev.off())8summary <- paste(plot_type, tail(y, 1), sep = ":")
    values this steptemporary PDF device closedgraphics device
  8. summary ← l:8

    7invisible(dev.off())8summary <- paste(plot_type, tail(y, 1), sep = ":")9cat(summary, "\n", sep = "")
    values this stepl:8summarylplot_type8tail(y, 1)
  9. cat(summary, " ", sep = "")

    8summary <- paste(plot_type, tail(y, 1), sep = ":")9cat(summary, "\n", sep = "")
    outputl:8
    values this stepl:8summary
  1. x ← 1, 2, 3, 4

    1x <- c(1, 2, 3, 4)2type_index <- 3
    values this step1, 2, 3, 4x
  2. type_index ← 3

    1x <- c(1, 2, 3, 4)2type_index <- 33plot_type <- c("p", "l", "b")[type_index]
    values this step3type_index
  3. plot_type ← b

    2type_index <- 33plot_type <- c("p", "l", "b")[type_index]4y <- x * 2
    values this stepbplot_type3type_index
  4. y ← 2, 4, 6, 8

    3plot_type <- c("p", "l", "b")[type_index]4y <- x * 25pdf(tempfile(fileext = ".pdf"))
    values this step2, 4, 6, 8y1, 2, 3, 4x
  5. graphics device ← temporary PDF device

    4y <- x * 25pdf(tempfile(fileext = ".pdf"))6plot(x, y, type = plot_type, main = "Growth")
    values this steptemporary PDF devicegraphics device
  6. plot ← Growth scatter plot (points and lines)

    5pdf(tempfile(fileext = ".pdf"))6plot(x, y, type = plot_type, main = "Growth")7invisible(dev.off())
    values this stepGrowth scatter plot (points and lines)plot1, 2, 3, 4x2, 4, 6, 8ybplot_type
  7. graphics device ← closed

    6plot(x, y, type = plot_type, main = "Growth")7invisible(dev.off())8summary <- paste(plot_type, tail(y, 1), sep = ":")
    values this steptemporary PDF device closedgraphics device
  8. summary ← b:8

    7invisible(dev.off())8summary <- paste(plot_type, tail(y, 1), sep = ":")9cat(summary, "\n", sep = "")
    values this stepb:8summarybplot_type8tail(y, 1)
  9. cat(summary, " ", sep = "")

    8summary <- paste(plot_type, tail(y, 1), sep = ":")9cat(summary, "\n", sep = "")
    outputb:8
    values this stepb:8summary
plot `plot(x, y, type = ...)` draws paired x/y values with the requested geometry.
type `type = "p"`, `"l"`, or `"b"` chooses points, lines, or both.
device A graphics device is where R sends drawing commands; here a temporary PDF device keeps the example deterministic.