The “plot” Function in R

  • Package: Base R (no specific package required)

  • Purpose: Creates various types of plots for visualizing data.

  • General Class: Data Visualization

  • Required Argument(s):

    • x: The x-axis variable.

    • y: The y-axis variable.

  • Notable Optional Arguments:

    • type: A character string specifying the type of plot. Options include “p” for points, “l” for lines, “b” for both, “c” for empty points with lines, “s” for stair steps, and more.

    • main: A main title for the plot.

    • xlab: A label for the x-axis.

    • ylab: A label for the y-axis.

    • col: The color of the plotted elements.

    • pch: The plotting symbol (integer or single character) for points.

    • lty: The line type.

    • xlim and ylim: Limits for the x and y axes.

    • ...: Additional graphical parameters.

  • Example:

  • # Example vectors
    x <- c(1, 2, 3, 4, 5)
    y <- c(2, 4, 6, 8, 10)

    # Create a scatter plot
    plot(x, y, type = "p", main = "Scatter Plot Example", xlab = "X-axis", ylab = "Y-axis", col = "blue", pch = 16)

  • In this example, the plot function is used to create a scatter plot of the vectors x and y. The type of plot, main title, axis labels, color of points, and plotting symbol are specified as additional arguments. The resulting scatter plot is then displayed.

Previous
Previous

The “abline” Function in R

Next
Next

The “hist” Function in R