Presentation is loading. Please wait.

Presentation is loading. Please wait.

Customizing Graphs Base graphics options. plot() The workhorse plotting function plot(x) plots values of x in sequence or a barplot plot(x, y) produces.

Similar presentations


Presentation on theme: "Customizing Graphs Base graphics options. plot() The workhorse plotting function plot(x) plots values of x in sequence or a barplot plot(x, y) produces."— Presentation transcript:

1 Customizing Graphs Base graphics options

2 plot() The workhorse plotting function plot(x) plots values of x in sequence or a barplot plot(x, y) produces a scatterplot plot(y~x, data=data.frame) produces a scatterplot Many statistical functions produce results that can be plotted using plot

3 Variations on plot() type = “p”, “l”, “b”, or “n” for points, lines, both, or no plot (also “c”, “o”, “h”, “s”, “S”) asp = sets the y/x aspect ratio (asp=1 for mapping) Full control over labels, axes, symbols, lines, etc

4 Parameter cex= cex controls the size of text and symbols in a graph cex = 1 is the default size (except for main= where it is 2) cex.main, cex.sub, cex.lab, cex.axis control specific parts of the plot cex = alone usually controls the size of pch, the plot character

5 Symbol/Line Styles pch = (plot character) specifies the symbol set cex = symbol size lty = specifies the line type lwd = specifies the line thickness

6

7

8

9 Parameter col= col = controls the color of a symbol or line col.axis, col.lab, col.main, col.sub control colors of other parts of the graph bg = background color col takes a name or hexadecimal color value

10 Color colors() for list of 657 named colors palette() gives the default list of eight colors gray() gives grayscale from black - gray(0) to white – gray(1)

11

12

13 Color Palettes rainbow(number) generates a spectrum from red to violet based on hue, saturation, and value (hsv) rainbow_hcl(number) similar, but using hue, chroma, and luminance color space (hcl) Help pages for these give several other palettes

14

15

16

17

18

19

20 Fonts family = sets the font family – “serif”, “sans”, and “mono” – others may be defined by specific graphic devices font = sets the font, 1 plain, 2 bold, 3 italic, 4 bold italic, 5 symbol Fonts may be device dependent

21

22 Labels main = “This is the title”, cex.main, col.main, font.main sub = “This is the subtitle”, cex.sub, col.sub, font.sub Axis labels –lab = “This is the x-axis label” –ylab = “This is the y-axis label” –cex.lab, col.lab, font.lab, las (0, 1, 2, 3)

23 Axes Default usually selects reasonable axes xlim, ylim set limits for axes xaxp, yaxp set tick marks xlog, ylog to use log scale xaxt, yaxt “n” suppresses plotting

24 axis() Use to add a customized axis or position an axis on the top or right of the plot or in the margin of the plot at = specifies location of tickmarks labels = specifies labels

25 Adding to a Graph 1 Plot sets up coordinates grid – add gridlines abline – add regression, vertical, or horizontal lines (full plot window) points – add points lines – add lines segment – add line segments

26 Adding to a Graph 2 text – add text to plot legend (locator, position, coords) arrows – draw arrows rect – draw rectangles polygon – draw polygons ellipse – draw probability ellipse matlines – draw multiple lines

27 Margins Must be set before calling plot oldpar <- par() # to save current par(mar= c(bottom, left, top, right)) if you need more space for labels, titles, etc

28 Multiple Graphs par(mfrow=c(rows, cols)) plots in rows Par(mfcol=c(rows, cols)) plots in columns


Download ppt "Customizing Graphs Base graphics options. plot() The workhorse plotting function plot(x) plots values of x in sequence or a barplot plot(x, y) produces."

Similar presentations


Ads by Google