num <- c(1,2,3,5,6,7)
plot(sort(num), sequence(table(num)),ylim=c(0,4.5),xlim=c(0,8),pch=19,axes=F, xlab='Numbers',ylab='',main='Property of Mean',col='darkblue')
axis(side=1)

segments(mean(num),0,mean(num),4,col='red',lty=1)

text(4,4.5,paste('mean=',round(mean(num),2)),col='red')

segments(mean(num),1,5,1,col='blue',lty=2)
segments(mean(num),1.5,6,1.5,col='blue',lty=2)
segments(mean(num),2,7,2,col='blue',lty=2)
text(4.5,1.2,'1')
text(5,1.7,'2')
text(5.5,2.2,'3')
text(6.2,3.5,'addition of the distances between \nthe points of the right of the mean line \nand mean = 6')

segments(mean(num),1,3,1,col='blue',lty=2)
segments(mean(num),1.5,2,1.5,col='blue',lty=2)
segments(mean(num),2,1,2,col='blue',lty=2)
text(3.5,1.2,'1')
text(3,1.7,'2')
text(2,2.2,'3')
text(1.8,3.5,'addition of the distances between \nthe points of the left of the mean line \nand mean = 6')

num <- c(1,1,1,2,2,2,3,4,3,5,7,5,7,6,6,5)
plot(sort(num), sequence(table(num)),pch=19, axes=F,ylim=c(0.5,5),xlab='NUMBERS',ylab='',col='blue',main='Property of Median')
axis(side=1)

segments(median(num),0,median(num),4.5,col='red',lty=1)
text(3.5,4.7,paste('median =', median(num)),col='red')

text(5.2,4,'numbers of points on the right \nof the median line = 8')
text(2,4,'numbers of points on the left \nof the median line = 8')

set.seed(13)
right <- rbeta(10000,2,20)*1000
hist(right,col='lightblue',breaks=50, freq=FALSE,main="",xlab="",ylab="", axes=F)
lines(density(right),lty=2)
axis(side=1)

abline(v=mean(right), col='darkblue', lwd=2)
abline(v=median(right), col='red', lwd=2)
legend('topright', legend=c('mean','median'), col=c('darkblue','red'), pch='|')
text(300,0.007,'If mean is greater than median, \nRIGHT SKEW !!')
text(350,0.0005,'TAIL')
title(main='Right SKEW')

set.seed(13)
right <- rbeta(10000,20,2)*1000
hist(right,col='lightblue',breaks=50, freq=FALSE,main="",xlab="",ylab="", axes=F)
lines(density(right),lty=2)
axis(side=1)

abline(v=mean(right), col='darkblue', lwd=2)
abline(v=median(right), col='red', lwd=2)
legend('topleft', legend=c('mean','median'), col=c('darkblue','red'), pch='|')
text(700,0.007,'If mean is less than median, \nLEFT SKEW !!')
text(650,0.0005,'TAIL')
title(main='LEFT SKEW')

set.seed(13)
normal = rnorm(10000, 100, 10)
m <- mean(normal)
hist(normal, col='lightgreen', border='white', freq=FALSE, breaks=30, ylim=c(0,0.05),main='Normal Distribution and its characteristics',axes=F,ylab='',xlab='')
axis(side=1)
lines(density(normal),lty=2,col='red') 
lines(c(m,m),c(0,0.043),col='darkblue',lwd=2,lty=2)
lines(c(median(normal),median(normal)), c(0,0.043), lwd=2, lty=3,col='black')
text(120,0.035,'mean and median lies\n close together')
arrows(109,0.035,mean(normal),0.035)
m = mean(normal)
p1sd = mean(normal) + sd(normal)
n1sd = mean(normal) - sd(normal)
p2sd = mean(normal) + 2*sd(normal)
n2sd = mean(normal) - 2*sd(normal)
p3sd = mean(normal) + 3*sd(normal)
n3sd = mean(normal) - 3*sd(normal)

lines(c(m,p1sd),c(0.0005,0.0005),lty=2)
text(105,0.0015,'1 SD')
lines(c(m,p2sd),c(0.0025,0.0025),lty=2)
text(105,0.0035,'2 SD')
lines(c(m,p3sd),c(0.005,0.005),lty=2)
text(105,0.006,'3 SD')

lines(c(p1sd,p1sd),c(0,0.043),col='blue',lty=2,lwd=2)
lines(c(n1sd,n1sd),c(0,0.043),col='blue',lty=2,lwd=2)

lines(c(p2sd,p2sd),c(0,0.0445),col='blue',lty=2,lwd=2)
lines(c(n2sd,n2sd),c(0,0.0445),col='blue',lty=2,lwd=2)

lines(c(p3sd,p3sd),c(0,0.047),col='blue',lty=2,lwd=2)
lines(c(n3sd,n3sd),c(0,0.047),col='blue',lty=2,lwd=2)

lines(c(n1sd,p1sd),c(0.042,0.042))
text(m, 0.043,'68% of data lies this area under the curve')

lines(c(n2sd,p2sd),c(0.0445,0.0445))
text(m, 0.0455, '95% of data lies this area under the curve')

lines(c(n3sd,p3sd),c(0.047,0.047))
text(m, 0.049, '99.7% of data lies this area under the curve')

num <- c(0,1,2,3,4,5,6,7,8,20)
q1 <- quantile(num,0.25)
q3 <- quantile(num,0.75)
iqr <- q3 - q1
u <- q3 + (1.5*iqr)
l <- q1 - (1.5*iqr)
plot(sort(num), sequence(table(num)),ylim=c(0.9,3),xlim=c(-10,25),pch=19,axes=F, xlab='Numbers',ylab='',col='blue')
axis(side=1)
title('Quantiles and Outliers')
segments(mean(num),0,mean(num),2,col='red',lty=2)
text(8,2,'mean',col='red')
arrows(8,1.9,mean(num)+0.1,1.5,lwd=1,col='red')

segments(median(num),0,median(num),2,col='blue',lty=2)
text(2,2,'median/\n50th percentile')
arrows(2,1.9,median(num)-0.1,1.5,col='blue')

segments(q1,0,q1,2.5,col='orange',lty=2)
text(0,1.5,'Q1')
arrows(0,1.4,q1-0.1,1.3,col='orange')

segments(q3,0,q3,2.5,col='orange',lty=2)
text(8,1.5,'Q3')
arrows(8,1.4,q3+0.1,1.3,col='orange')

lines(c(quantile(num,0.25),quantile(num,0.75)),c(2.5,2.5))
text(median(num),2.6,'IQR',)

segments(u, 0, u, 2, col='darkblue',lty=2)
text(u+1,2.2,'above this line are outliers\nQ3 + 1.5*IQR')

segments(l, 0, l, 2, col='darkblue', lty=2)
text(l-1, 2.2, 'below this line are outliers\nQ1 - 1.5*IQR')
text(5,3,'data = 0,1,2,3,4,5,6,7,8,20')

num <- c(0,1,2,3,4,5,6,7,8,20)
q1 <- quantile(num,0.25)
q3 <- quantile(num,0.75)
iqr <- q3 - q1
u <- q3 + (1.5*iqr)
l <- q1 - (1.5*iqr)
boxplot(num, horizontal = TRUE, ylim=c(-10,25), xlim=c(0.7,2), axes=F, xlab='Boxplot')
axis(side=1)
title('BOXPLOT')

text(3,1.65,'median/\n50th percentile',col='blue')
arrows(3,1.55,median(num)-0.1,1.2,col='blue')

text(-5,1.3,'Q1',col='orange')
arrows(-5,1.25,q1-0.2,1.2,col='orange')


text(13,1.3,'Q3',col='orange')
arrows(13,1.25,q3+0.2,1.2,col='orange')

lines(c(q1-0.3,q3+0.3),c(0.75,0.75))
text(median(num),0.7,'IQR',)

text(20,1.4,'Outlier (upper)',col='red')
arrows(20,1.35,20,1.05, col='red')
text(0,2,'BOX SHAPE is drawn at the range of IQR')

num <- c(2,4,5,7,8,10)
y <- c(1.1,1.2,1.3,1.4,1.5,1.6)
m <- mean(num)
plot(sort(num), sequence(table(num)),pch=19,axes=F, xlab='Numbers',ylab="", xlim=c(0,12),ylim=c(0.9,2))
axis(side=1)
title('VARIANCE')
abline(v=mean(num),col='blue',lty=2,lwd=3)
text(5,1.9,'mean',col='blue')
arrows(5,1.85,m,1.7,col='blue')
l <- function(x1,y){
    lines(c(m,x1),c(y,y),lty=2, col='red',lwd=3)
    text((m+x1)/2,y+0.05,paste(x1-m,'x',x1-m))
}
for (i in 1:length(num)){
    l(num[i],y[i])
}
text(2,1.9,'Variance = average of sum\nof distance squared from\nthe mean')

v1 <- c(1:5)
v2 <- c(3:7)
plot(v1, v2, pch=19, col='blue',axes=F)
axis(side=1)
axis(side=2)
title('COVARIANCE')
abline(v=3,h=5,col='orange',lty=2,lwd=3)
text(1.5,6,'Mean of v2')
text(2,6.5,'Mean of v1')
arrows(1.5,5.9,1.5,5)
arrows(2.3,6.5,3,6.5)

lines(c(1,1),c(3,5),lty=2,col='red',lwd=2)
lines(c(2,2),c(4,5),lty=2,col='red',lwd=2)
lines(c(4,4),c(6,5),lty=2,col='red',lwd=2)
lines(c(5,5),c(7,5),lty=2,col='red',lwd=2)

lines(c(1,3),c(3,3),lty=2,col='red',lwd=2)
lines(c(2,3),c(4,4),lty=2,col='red',lwd=2)
lines(c(4,3),c(6,6),lty=2,col='red',lwd=2)
lines(c(5,3),c(7,7),lty=2,col='red',lwd=2)

text(1.1,4,'-2')
text(2,3.1,'-2')
text(2.5,4.1,'-1')
text(2.1,4.5,'-1')
text(3.1,4.9,'0,0')
text(4.1,5.5,'1')
text(3.5,6.1,'1')
text(4.9,6,'2')
text(4,6.9,'2')
text(4,4.8,'')

text(4,4,'average of the product \nof distances from two means')