# First, create the plot (without labels initially)
plot(x, y) # Replace x and y with your actual data
# Then, add the axis labels using title()
title(xlab="Your X-axis Label", ylab="Your Y-axis Label")
Explanation:
title(): This function adds titles and labels to your plot.
xlab="Your X-axis Label": This sets the label for the x-axis. Replace "Your X-axis Label" with the actual label you want.
ylab="Your Y-axis Label": This sets the label for the y-axis. Replace "Your Y-axis Label" with the actual label you want.
Example:
Let's say you plotted height versus age without labels:
age <- c(5, 10, 15, 20, 25)
height <- c(40, 55, 65, 70, 72)
plot(age, height) # No labels initially
# Now add the labels:
title(xlab = "Age (years)", ylab = "Height (inches)")
Alternative: Directly in the plot() function
It's also good practice to include axis labels when you initially create the plot using the plot() function itself:
plot(x, y, xlab="Your X-axis Label", ylab="Your Y-axis Label")
This avoids needing to call title() separately and generally makes your code more readable. Using the example above:
While you can add labels after plotting with title(), it's often better and more concise to specify xlab and ylab directly within the plot() function call when you initially create the plot.