The graphics package
As it was mentioned before, graphics
is the most basic graphical package in R. As with any other package, it contains a wide variety of functions (all dedicated to graphics, of course) but plot()
is the most important one. plot()
is a special type of function called a generic function, which is a function that can receive inputs of different classes but produces different outputs according to the class of the input.
This can be simply appreciated by plotting the different variables of the iris
dataset:
Variable type |
Plot |
---|---|
If a character or factor vector is passed (such as
plot(iris$Species)
| |
If a numeric vector is passed, a dispersion graph is returned:
plot(iris$Sepal.Length)
| |
If two numeric vectors are passed, a scatterplot is returned:
plot(iris$Sepal.Length,iris$Sepal.Width)
| |
If a numeric data frame or matrix is passed, a multiple scatterplot is created:
plot(iris)
|
As you might have already...