Sunday, March 2, 2014

Basic plots in R, plot, boxplot and hist

There is tens of way to plot a set in R. Today I will just present you 3 of them:
  • plot
  • boxplot
  • hist
To simply plot a vector of values, you can simply use the function plot. Try this:
# Get some data to plot
data(iris)
plot(iris$Sepal.Length)

To have a better idea of the distribution the function boxplot is really useful:
# one set
boxplot(iris$Sepal.Length)
# 2 sets
boxplot(data.frame(iris$Sepal.Length, iris$Sepal.Width))
Finally if you need more details on the distribution you will use hist:
hist(iris$Sepal.Length)

No comments:

Post a Comment