How to create Histograms plots in R

In [2]:
# -------------------------------------------------
# How to create Histograms plots in R
# -------------------------------------------------
# load library and data
library(mlbench)
data(mtcars)
dim(mtcars)

# Creating a Graph
par(mfrow=c(1,1))

plot(mtcars$wt, mtcars$mpg) 
abline(lm(mtcars$mpg ~ mtcars$wt))
title("Regression of MPG on Weight")

# Simple Histogram
hist(mtcars$mpg)

# Colored Histogram with Different Number of Bins
par(mfrow=c(1,3))
hist(mtcars$mpg, breaks=12, col="red")
hist(mtcars$hp, breaks=11, col="green")
hist(mtcars$wt, breaks=10, col="blue")
  1. 32
  2. 11
In [ ]: