barplot( frequency ,
main = "Title of the graph" ,
xlab = "Label of the horizontal line" ,
ylab = "Label of the vertical line" ,
col = "color-name/code" ,
border = "color-of-the-border" ,
space = #space ,
ylim = c(#start, #end ) )
HairColor: blonde, black, brown, silver, red, brown, brown, black, blonde, black
# generate variable HairColor
HairColor <- c("blonde", "black", "brown", "silver", "red", "brown", "brown", "black", "blonde", "black")
# generate the frequency for HairColor because barplot() needs the frequency to plot.
HairColor.freq <- table(HairColor)
HairColor.freq
## HairColor
## black blonde brown red silver
## 3 2 3 1 1
# generate bar plot using barplot()
barplot(HairColor.freq,
main = "Bar Graph of Hair Colors",
xlab = "Different Hair Colors",
ylab = "Number of Students",
ylim = c(0, 4),
col = "lightblue",
border = "tomato2",
space = 0.8)
hist( data/variable/vector ,
main = "Title of the graph" ,
xlab = "Label of the horizontal line" ,
ylab = "Label of the vertical line" ,
col = "color-name/code" ,
border = "color-of-the-border" ,
ylim = c(#start, #end ) )
Score1: 18.5, 19.5, 20, 22, 18.5, 17, 16, 18, 11.5, 10.5, 20, 22.5, 16.5, 13, 11.5, 19, 22, 22, 21, 19.5, 12.5, 21
# generate variable
Score1 <- c( 18.5, 19.5, 20, 22, 18.5, 17, 16, 18, 11.5, 10.5, 20, 22.5, 16.5, 13, 11.5, 19, 22, 22, 21, 19.5, 12.5, 21)
# histogram
hist(Score1,
main = "Histogram of Exam 1 Score Before Extra Credit",
ylab = "Number of Students",
xlab = " Exam Scores",
ylim = c(0,9),
col = "steelblue",
border = "khaki")
Score2: 20.5, 22.5, 21.5, 24,21, 20, 18, 20.5, 14.5, 13, 22.5, 25.5, 19, 14, 11.5, 21, 24.5, 24.5, 23.5, 22.5, 14.5, 22