#############Chapter 1: Summarizing and Displaying Data###################
####Earthquake data, # earthquakes of magnitude 7 or greater for years 1980-1990:
eq<-c(18,14,10,15,8,15,6,11,8,7,12,11,23,16,15,25,22,20,16,23)
eq
#### mean 
mean(eq)
#### variance
var(eq)
#### standard deviation
sd(eq)
#or
sqrt(var(eq))  
#### sorting
sort(eq)
#### quartiles
median(eq)
fivenum(eq)
##Range
fivenum(eq)[5] - fivenum(eq)[1]
##IQR
fivenum(eq)[4] - fivenum(eq)[2]
diff(fivenum(eq)[c(2,4)])


#### stripchart-ggplot
# stripchart (dotplot) using R base graphics
# main is the title, xlab is x-axis label (ylab also available)
# par() gives graphical options
# mfrow = "multifigure by row or column" 
# 2 rows, 1 column
par(mfrow=c(2,1))
stripchart(eq, main="Earthequake", xlab="Number of Earthquakes")
stripchart(eq, method="stack", main="Earthequake, method is stack",xlab="Number of Earthquakes")

#### hist
# histogram using R base graphics
par(mfrow=c(1,2))
hist(eq, main="Earthquake", xlab="Number of Earthquakes")
# breaks are how many bins-1 to use
# freq=FALSE changes the vertical axis to density,
# so the total area of the bars is now equal to 1
hist(eq, breaks = 10, freq = FALSE, main="Histogram, density")

#### stem-and-leaf
# stem-and-leaf plot
stem(eq)
# scale=2 makes plot roughly twice as wide
stem(eq, scale=2)

#### Box-plot
par(mfrow=c(1,1))
boxplot(eq, horizontal=FALSE, main="Earthquake", xlab="Number of earthquakes")

##plot data
x<-seq(1:20)
plot(x,eq,main="Scatterplot of Earthquake Data")