Based Plot: Scatter Plot

Published

November 5, 2024

Modified

September 24, 2025

Full Screen

๐Ÿ“Š Scatter Plot Cheat Sheet (R Base)

Command Purpose
plot(x, y) Basic scatter plot of two variables
main = "Title" Add main title
xlab = "X-axis", ylab = "Y-axis" Axis labels
pch Point shape (0 = square, 1 = circle, 2 = triangle, โ€ฆ)
col Point border color
bg Point fill color (only for pch = 21โ€“25)
cex Point size (default = 1)
legend(position, legend, col, pch, title) Add legend to explain groups
text(x, y, labels, pos, col) Annotate points with text
abline(lm(y ~ x, data=df), col) Add linear regression line
lines(lowess(x, y), col) Add smooth (non-linear) line
data(iris), data(cars), data(gapminder) Example datasets for plotting
dplyr::mutate() with if_else() or case_when() Conditional coloring or symbols
RColorBrewer::display.brewer.all() Show all color palettes
brewer.pal(n, "Accent") Extract n colors from palette
par(bg="lightblue") Change background color
rect(..., col="gray") Fill plot box background
grid(lty=1, col="white") Add grid lines

Quick Tips:

  • Use pch and col to differentiate groups.

  • Combine abline() and lines(lowess()) to show both linear and non-linear fits.

  • Use RColorBrewer for professional, colorblind-friendly palettes.

  • Control background and grid with par(), rect(), and grid().