Learn how to create a basic scatter plot in R using the base plot() function with random data, titles, and color customization for beginners.
# Set the seed for reproducibility of random data
set.seed(123)
# Generate 50 random points for the x-axis with normal distribution
x <- rnorm(50)
# Generate 50 random points for the y-axis with normal distribution
y <- rnorm(50)
# Create a basic scatter plot with plot()
plot(x, y,
main = "Basic Scatter Plot with plot()",
xlab = "X Axis",
ylab = "Y Axis",
col = "blue", # Color of the points
pch = 19) # Point type: solid circleR base: no external library required
plot() function: base R function to create plots
set.seed(): for reproducibility of random data
Data generated with rnorm(): generation of random numbers with normal distribution
Plot configuration: titles, axis labels, point color
Plot output: visualization in R graphical window (RStudio or R GUI)