data("anscombe")
str(anscombe)
## 'data.frame':    11 obs. of  8 variables:
##  $ x1: num  10 8 13 9 11 14 6 4 12 7 ...
##  $ x2: num  10 8 13 9 11 14 6 4 12 7 ...
##  $ x3: num  10 8 13 9 11 14 6 4 12 7 ...
##  $ x4: num  8 8 8 8 8 8 8 19 8 8 ...
##  $ y1: num  8.04 6.95 7.58 8.81 8.33 ...
##  $ y2: num  9.14 8.14 8.74 8.77 9.26 8.1 6.13 3.1 9.13 7.26 ...
##  $ y3: num  7.46 6.77 12.74 7.11 7.81 ...
##  $ y4: num  6.58 5.76 7.71 8.84 8.47 7.04 5.25 12.5 5.56 7.91 ...
mean(anscombe$x1)
## [1] 9
lapply(anscombe, mean)
## $x1
## [1] 9
## 
## $x2
## [1] 9
## 
## $x3
## [1] 9
## 
## $x4
## [1] 9
## 
## $y1
## [1] 7.500909
## 
## $y2
## [1] 7.500909
## 
## $y3
## [1] 7.5
## 
## $y4
## [1] 7.500909
lapply(anscombe, sd)
## $x1
## [1] 3.316625
## 
## $x2
## [1] 3.316625
## 
## $x3
## [1] 3.316625
## 
## $x4
## [1] 3.316625
## 
## $y1
## [1] 2.031568
## 
## $y2
## [1] 2.031657
## 
## $y3
## [1] 2.030424
## 
## $y4
## [1] 2.030579
cor(anscombe$x1,anscombe$y1)
## [1] 0.8164205
attach(anscombe)
cor(x2,y2)
## [1] 0.8162365
cor(x3,y3)
## [1] 0.8162867
cor(x4,y4)
## [1] 0.8165214
par(mfrow=c(2,2))
plot(x1,y1)
plot(x2,y2)
plot(x3,y3)
plot(x4,y4)

data(iris)
str(iris)
## 'data.frame':    150 obs. of  5 variables:
##  $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
##  $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
##  $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
##  $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
##  $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
plot(iris)

plot(iris[3:5])

plot(iris$Sepal.Length)
par(mfrow=c(1,1))

plot(iris$Sepal.Length)

plot(iris$Sepal.Length,iris$Species)

stem(iris$Sepal.Length)
## 
##   The decimal point is 1 digit(s) to the left of the |
## 
##   42 | 0
##   44 | 0000
##   46 | 000000
##   48 | 00000000000
##   50 | 0000000000000000000
##   52 | 00000
##   54 | 0000000000000
##   56 | 00000000000000
##   58 | 0000000000
##   60 | 000000000000
##   62 | 0000000000000
##   64 | 000000000000
##   66 | 0000000000
##   68 | 0000000
##   70 | 00
##   72 | 0000
##   74 | 0
##   76 | 00000
##   78 | 0
boxplot(iris$Sepal.Length)

boxplot(iris$Sepal.Length~iris$Species)

table(iris$Sepal.Length,iris$Species)
##      
##       setosa versicolor virginica
##   4.3      1          0         0
##   4.4      3          0         0
##   4.5      1          0         0
##   4.6      4          0         0
##   4.7      2          0         0
##   4.8      5          0         0
##   4.9      4          1         1
##   5        8          2         0
##   5.1      8          1         0
##   5.2      3          1         0
##   5.3      1          0         0
##   5.4      5          1         0
##   5.5      2          5         0
##   5.6      0          5         1
##   5.7      2          5         1
##   5.8      1          3         3
##   5.9      0          2         1
##   6        0          4         2
##   6.1      0          4         2
##   6.2      0          2         2
##   6.3      0          3         6
##   6.4      0          2         5
##   6.5      0          1         4
##   6.6      0          2         0
##   6.7      0          3         5
##   6.8      0          1         2
##   6.9      0          1         3
##   7        0          1         0
##   7.1      0          0         1
##   7.2      0          0         3
##   7.3      0          0         1
##   7.4      0          0         1
##   7.6      0          0         1
##   7.7      0          0         4
##   7.9      0          0         1
table(iris$Species,iris$Sepal.Length)
##             
##              4.3 4.4 4.5 4.6 4.7 4.8 4.9 5 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8
##   setosa       1   3   1   4   2   5   4 8   8   3   1   5   2   0   2   1
##   versicolor   0   0   0   0   0   0   1 2   1   1   0   1   5   5   5   3
##   virginica    0   0   0   0   0   0   1 0   0   0   0   0   0   1   1   3
##             
##              5.9 6 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7 7.1 7.2 7.3 7.4
##   setosa       0 0   0   0   0   0   0   0   0   0   0 0   0   0   0   0
##   versicolor   2 4   4   2   3   2   1   2   3   1   1 1   0   0   0   0
##   virginica    1 2   2   2   6   5   4   0   5   2   3 0   1   3   1   1
##             
##              7.6 7.7 7.9
##   setosa       0   0   0
##   versicolor   0   0   0
##   virginica    1   4   1
barplot(table(iris$Sepal.Length,iris$Species))

barplot(table(iris$Species,iris$Sepal.Length))

barplot(table(iris$Species,iris$Sepal.Length),col=rainbow(7))

table(iris$Sepal.Length)
## 
## 4.3 4.4 4.5 4.6 4.7 4.8 4.9   5 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9   6 
##   1   3   1   4   2   5   6  10   9   4   1   6   7   6   8   7   3   6 
## 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9   7 7.1 7.2 7.3 7.4 7.6 7.7 7.9 
##   6   4   9   7   5   2   8   3   4   1   1   3   1   1   1   4   1
par(mfrow=c(1,2))
table(iris$Species)
## 
##     setosa versicolor  virginica 
##         50         50         50
pie(table(iris$Species))
barplot(table(iris$Species))

attach(iris)

hist(Sepal.Length)
hist(Sepal.Length,breaks = 20)

plot(density(Sepal.Length))
hist(Sepal.Length,breaks = 20)
rug(Sepal.Length)

hist(Sepal.Length,breaks = 20)
 par(mfrow=c(2,3))

 par(bg="white")
 
 plot(iris$Sepal.Length,col=rainbow(6))
 hist(iris$Sepal.Length,col=rainbow(6))
 boxplot(iris$Sepal.Length,col=rainbow(6))
 plot(iris$Sepal.Length,iris$Species,col=rainbow(6))
 hist(iris$Sepal.Length,breaks=10,col=rainbow(6))
 boxplot(iris$Sepal.Length~iris$Species,col=rainbow(6))

par(bg="grey")
plot(iris$Sepal.Length,col=rainbow(6))
hist(iris$Sepal.Length,col=rainbow(6))
boxplot(iris$Sepal.Length,col=rainbow(6))
plot(iris$Sepal.Length,iris$Species,col=rainbow(6))
hist(iris$Sepal.Length,breaks=10,col=rainbow(6))
boxplot(iris$Sepal.Length~iris$Species,col=rainbow(6))

par(bg="yellow")
plot(iris$Sepal.Length,col=rainbow(6))
hist(iris$Sepal.Length,col=rainbow(6))
boxplot(iris$Sepal.Length,col=rainbow(6))
plot(iris$Sepal.Length,iris$Species,col=rainbow(6))
hist(iris$Sepal.Length,breaks=10,col=rainbow(6))
boxplot(iris$Sepal.Length~iris$Species,col=rainbow(6))

par(mfrow=c(1,1))

par(bg="yellow")
boxplot(iris$Sepal.Length~iris$Species,main="This is a box plot")

par(mfrow=c(1,2))

par(bg="grey")
boxplot(iris$Sepal.Length~iris$Species,xlim=c(0.1,2.5),xlab="Species",ylab="Sepal Length",main= "Boxplot")
hist(iris$Sepal.Length,ylab="Sepal Length",main= "Histogram")

hist(iris$Sepal.Length,col=topo.colors(3))
hist(iris$Sepal.Length,col=topo.colors(8))

hist(iris$Sepal.Length,col=topo.colors(8,0.1))
hist(iris$Sepal.Length,col=topo.colors(8,0.9))

par(mfrow=c(2,3))

hist(iris$Sepal.Length,col=cm.colors(8),main="cm")
hist(iris$Sepal.Length,col=topo.colors(8),main="topo")
hist(iris$Sepal.Length,col=rainbow(8),main="rainbow")
hist(iris$Sepal.Length,col=heat.colors(8),main="heat")
hist(iris$Sepal.Length,col=terrain.colors(8),main="terrain")

library(RColorBrewer)
display.brewer.all()

library(RColorBrewer)
par(mfrow=c(2,3))
hist(VADeaths,col=brewer.pal(3,"Set3"),main="Set3 3 colors")
hist(VADeaths,col=brewer.pal(3,"Set2"),main="Set2 3 colors")
hist(VADeaths,col=brewer.pal(3,"Set1"),main="Set1 3 colors")
hist(VADeaths,col=brewer.pal(8,"Set3"),main="Set3 8 colors")
hist(VADeaths,col=brewer.pal(8,"Greys"),main="Greys 8 colors")
hist(VADeaths,col=brewer.pal(8,"Greens"),main="Greens 8 colors")