Based Plot: Modified Plot

Published

November 5, 2024

Modified

September 24, 2025

Full Screen

Modified Plot — Extended Quick Reference (R Base)

Topic Command / Argument What it does Example
Basic plot plot(x, y, …) Create a scatter plot plot(mtcars$wt, mtcars$mpg)
Axis labels & limits xlab, ylab, xlim, ylim Label axes and set ranges plot(..., xlab="Weight", ylim=c(10,35))
Suppress axes axes=FALSE Hide axes, add custom later plot(..., axes=FALSE)
Custom axes axis(side, at, labels) Add ticks & labels manually axis(1, at=seq(1,6,1))
Box box() Add border around plot region box()
Point shape pch=0–25 Choose plotting symbol plot(..., pch=19)
Point size cex Change point size (default=1) plot(..., cex=2)
Point colors col, bg Border color & fill color (pch 21–25) plot(..., pch=21, col="black", bg="red")
Titles main, sub Add main and subtitle plot(..., main="Cars", sub="mtcars dataset")
Grid grid(nx, ny, col, lty, lwd) Add reference grid grid(col="gray", lty=2)
Regression line abline(lm(y~x)) Add linear regression line abline(lm(mpg~wt, mtcars))
Custom line lines(x, y, …) Add connected line to plot lines(lowess(x,y), col="blue")
Horizontal/Vertical line abline(h=…), abline(v=…) Add constant reference lines abline(h=20, col="red")
Text annotations text(x, y, labels, …) Add labels to points text(mtcars$wt, mtcars$mpg, rownames(mtcars))
Point labels identify(x, y, labels) Click to label interactively identify(mtcars$wt, mtcars$mpg, rownames(mtcars))
Legend legend(loc, legend, col, pch, …) Add legend legend("topright", c("Auto","Manual"), col=c("red","blue"), pch=19)
Margins par(mar=c(b,l,t,r)) Adjust plot margins par(mar=c(5,5,4,2))
Background (device) par(bg=…) Change device background color par(bg="lightblue")
Plot region background rect(par("usr")…) Fill plot panel background rect(usr1,usr3,usr2,usr4, col="lightyellow")
Multiple plots (row) par(mfrow=c(r,c)) Layout row-wise par(mfrow=c(2,2))
Multiple plots (col) par(mfcol=c(r,c)) Layout column-wise par(mfcol=c(2,2))
Custom layout layout(matrix(...)) Flexible arrangements layout(matrix(c(1,2,3,3),2,byrow=TRUE))
Save plot png("file.png"); plot(...); dev.off() Save as PNG (also pdf(), jpeg(), svg()) png("scatter.png"); plot(x,y); dev.off()
Fine text control cex.main, cex.lab, cex.axis Scale title/label/axis text plot(..., cex.lab=1.5)
Colors palette(), RColorBrewer, hex codes Define custom color sets col="#1f77b4"

Extra Tips

  1. Transparency: use rgb(r,g,b,alpha=…) or custom functions to make points transparent. Example:
   plot(x,y, col=rgb(0,0,1,0.3), pch=19)
  1. Export quality plots: use pdf() for vector graphics (for publications), png() with high resolution for slides.

  2. Consistency: set global styles with par() once (font, margins, bg) before plotting multiple figures.

  3. Interactivity: identify() is great for exploratory analysis to label points directly.

  4. Reproducibility: always add axis labels, titles, and legends—good practice for teaching and publication.