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.

scatter_plot_mapping.R
x <- c(1, 2, 3, 4)
type_index <- 
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 <- 
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 <- 
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 = "")
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.