CREATE A NEW PLOT Bar charts barplot(height, …) bar labels names.arg = border border = fill color col = horizontal horiz = TRUE Box plots boxplot(x, …) horizontal horizontal = TRUE box labels names = Dot plots dotchart(x, …) dot labels labels = Histograms hist(x, …) breakpts breaks = Scatterplots plot(x, …) symbol pch = Line charts plot(x, type = “l” ) line type lty = “blank”|0 “solid”|1 “dashed”|2 “dotted”|3 line width lwd = axis labels ann = FALSE axis, tickmarks, xaxt = “n” yaxt = “n”and labels plot box bty = “n” REMOVE ADJUST allow plotting out of plot xpd = TRUE region aspect ratio asp = axis limits xlim =, ylim = axis lines to xaxs = “i” , match axis limits yaxs = “i” (internal axis calculation) SET GRAPHICAL PARAMETERS multiple mfcol = c(nrow,ncol) plots mfrow = c(nrow,ncol) plot margins mar = c(bottom, left, top, right) default: c(5.1, 4.1, 4.1, 2.1) lines the following can only be set with par() plot margins oma = c(bottom, left, (outer) top, right) default: c(0, 0, 0, 0) lines query x & y par (“usr”) limits par (…) NOTE: Many of the parameters here can be also be set in par(). See R help for more options. Axes axis (side,… ) • location side = 1 2 3 4 (bottom, left, top, right) tick mark: • labels labels = • location at = • remove tick = FALSE • rotate text las = 1 (horizontal) Text text (x, y, text,…) • position • (rel. to x,y) pos = 1 2 3 4 (below, left, above, right) (default=center) Axis labels mtext (text,… ) • location side = 1 2 3 4 (bottom, left, top, right) • lines to skip line = (from plot region, default = 0) • position at = x or y-coord (depending on side) • justification adj = 0 .5 1 (left, center, right) Lines lines (x,…) • line style lty = • line width lwd = • color col = Title title (main,…) • axis labels xlab =, ylab = • subtitle sub = • title main = ADD TO AN EXISTING PLOT Add new plot [any plot function] (…,add = TRUE) ex. barplot(x, add = TRUE) • color col = • fill color bg = (pch: 21-25 only) location axis labels xlab =, ylab = subtitle sub = title main = style font face font = 1 (plain) 2 (bold) 3 (italic) 4 (bold italic) font family family = “serif” “sans” “mono” ADD TEXT Points points (x,…) • symbol pch = size (magnification factor) all elements cex = axis labels cex.lab = subtitle cex.sub = tick mark labels cex.axis = title cex.main = position text direction las = 1 (horizontal) justification adj = 0 .5 1 (left, center, right) R Base Graphics Cheatsheet Joyce  Robbins,  joycerobbins1@gmail.com