Introduction
Labels and titles help explain what your graphs or charts show. They make your data easier to understand.
Labels and titles help explain what your graphs or charts show. They make your data easier to understand.
plot(x, y, main = "Main Title", xlab = "X-axis Label", ylab = "Y-axis Label")
main adds the main title to the plot.
xlab and ylab add labels to the x-axis and y-axis.
plot(1:5, 1:5, main = "Simple Line", xlab = "Index", ylab = "Value")
barplot(c(3, 7, 2), main = "Bar Chart", xlab = "Categories", ylab = "Counts")
plot(1:10, (1:10)^2, main = "Square Numbers")
This program plots points from x and y with a main title and axis labels to explain the data.
x <- 1:5 y <- c(2, 4, 6, 8, 10) plot(x, y, main = "My Line Plot", xlab = "X Values", ylab = "Y Values")
You can add subtitles and captions using title(sub = "Subtitle") and mtext("Caption", side = 1).
Labels and titles improve the clarity and professionalism of your graphs.
Labels name the axes to show what data they hold.
Titles explain what the whole graph is about.
Use main, xlab, and ylab to add these in R plots.
main in an R plot?main in plottingmain argument in R's plot function is used to set the main title of the graph.xlab and ylab are used for x-axis and y-axis labels respectively, not main.ylab is used to set the label for the y-axis.plot(x, y, ylab = "Height") correctly assigns "Height" as the y-axis label.plot(1:5, 1:5, main = "Sales Over Time", xlab = "Month", ylab = "Sales")
main = "Sales Over Time" sets the main title of the plot.xlab = "Month" and ylab = "Sales" set the x-axis and y-axis labels, not the main title.plot(x, y, main = "Data", xlabel = "Time", ylab = "Value")
xlab, not xlabel.main is correct for the title, and ylab is correct for y-axis label.main for the title, xlab for the x-axis label, and ylab for the y-axis label.xlabel. plot(years, temps, main = "Temperature Trends", xlab = "Year") misses the y-axis label.Pass the test and this pattern moves unknown