← Back to R Course | Chapter 10: Data Visualization | Lesson 1 of 7

plot()

In this page:

  1. plot()

plot()

plot(x, y) is R's general-purpose base plotting function, drawing a scatter plot by default from two numeric vectors. Judge0 (and other non-interactive environments) capture plot output as a saved image rather than displaying a window. plot() accepts many arguments (type, col, pch, etc.) to customize its appearance.

Note: type = "l" draws a line plot instead of scattered points; type = "b" draws both points and connecting lines.

Example: plot()

markup
x <- 1:10
y <- x^2

# In a graphical R environment this renders a plot window / image file.
# Here we just confirm the data plot() would use is correct:
cat("x values:", x, "\n")
cat("y values:", y, "\n")
cat("plot(x, y) would draw a scatter plot of y = x^2\n")
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.