Histogram Trial (Day 1)

##############################################################################
#=== Plotting Histogram from Dat values (with class boundary information) ===#
##############################################################################

x = c(56, 65, 98, 82, 64, 71, 78, 95, 59,75,99, 73, 69, 70, 71, 80, 76, 82, 85,77)

#=== Option 1 ===#

# 1. Frequency #
gh = hist(x, col="blue", right = F)

#=== Option 2 ===#
library(lattice) # make sure you have installed the package

# 1. Frequency #
histogram(x, col = "blue", type = "count", endpoints = c(50, 100), nint = 5, right = F, ylab = "Frequency")

# 2. Relative frequency #
histogram(x, col = "red", endpoints = c(50, 100), nint = 5, right = F, ylab = "Relative frequency (%)")

####################################################################################################################

###################################################################################
#=== Plotting Histogram from Frequency table (with class boundary information) ===#
###################################################################################

#=== Option 1 ===#

# 1. Frequency #
Overall.Cond = seq(1, 11, by = 1) # Sequence of class boundaries #
Freq = c(15,5,2,3,2,1,7,12,4,10) # Frequencies #

myhist = list(breaks=Overall.Cond, counts=Freq, density=Freq/diff(Overall.Cond), xname = "x")

class(myhist) = "histogram"

plot(myhist, col = "cyan")

#=== Option 2 ===#
# 2. Relative frequency #
Overall.Cond = seq(1, 11, by = 1) # Sequence of class boundaries #
RF_Freq = (c(15,5,2,3,2,1,7,12,4,10)/sum(Freq))*100# Relative frequencies (%) #


myhistRF = list(breaks = Overall.Cond, counts = RF_Freq, density = RF_Freq/diff(Overall.Cond), xname = "x")

class(myhistRF) = "histogram"

plot(myhistRF, col = "blue", ylab = "Relative frequency (%)")