Plotting Basics

R's built-in plot() turns a vector into a chart with one line of code — the fastest way to actually look at your data instead of just staring at a column of numbers.

A basic scatter plot

R plot.R
scores <- c(88, 92, 79, 95, 84)
plot(scores)

Running this opens a plotting window showing five points, one per score, positioned by their index along the x-axis (1 through 5) and their value along the y-axis (79 through 95) — handing plot() a single vector defaults to plotting each value against its position.

A bar chart

R barplot.R
scores <- c(Math = 88, Science = 92, Art = 79)
barplot(scores, main = "Test Scores")

This produces three vertical bars labeled Math, Science, and Art along the x-axis, each rising to its score on the y-axis, with "Test Scores" printed as the chart's title. Naming the vector's elements (Math = 88, and so on) is what gives barplot() its axis labels for free.

Labeling axes and choosing a plot type

R labeled-plot.R
plot(scores, main = "Student Scores", xlab = "Student", ylab = "Score", type = "b")

main, xlab, and ylab set the title and axis labels, and type = "b" ("both") draws the points connected by lines instead of the plain dots the earlier example produced.

Note: In RStudio, a plot appears automatically in the Plots pane. Running the same script from a terminal with Rscript tries to open a graphics window instead — and on a server or other headless environment with no display, that can fail or produce nothing at all. Saving a plot to a file directly with png("chart.png"), then your plotting code, then dev.off(), sidesteps the problem entirely and is the standard way to generate a chart from a script that won't be run interactively.
Course complete: That covers the R course from top to bottom — variables and R's core types, vectors and how operations apply across every element at once, operators, conditionals, loops, functions with default arguments, data frames as R's table structure, the built-in statistics functions, and turning a vector straight into a chart with plot(). From here, the natural next step is exploring a real dataset — R's own built-in ones like mtcars or iris are a good place to practice everything covered here.