1 / 28

Customizing Graphs

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 a scatterplot plot( y~x , data= data.frame ) produces a scatterplot

lois
Download Presentation

Customizing Graphs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. 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

  7. 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)

  8. 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

  9. 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

  10. 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)

  11. 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

  12. 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

  13. 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

  14. 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

  15. 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

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

More Related