The plot function

plot() is a generic plotting function that produces a variety of basic plots, depending of the class of its arguments.

  Plots
plot(x)
  • A time series plot if x is a time series
  • A sequence plot if x is numerical vector
  • A bar chart if x is a factor
  • A scatterplot matrix, if x is a data frame
plot(x,y) )
  • Scatterplot of y against x , if both arguments are numeric
  • A parallel boxplot if x is a factor and y is numeric
  • A dotplot if y is a factor and x is numeric<
plot(y~x) Using a formula (presence of ~) you can also specify plot(x~y,data=frame)
  • A scatterplot if both x and y are numeric
  • A stacked barchart of x is a factor and y numeric
  • A boxplot if y is a factor and x numeric
plot(y ~expr) expr can be a single vector or an expression of the form X1+X2+X3; produces a scatterplot for each y,x combination (click the graph to view the next graph in the sequence).

Also, depending on the type of data, plot() the plot may be adapted; for instance when you are using time series data, points will automatically be connected by lines.

data(sunspots)
plot(sunspots)

The data() makes the sunspots data available (many datasets are included in R or in pacakges.