-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHistograms.R
More file actions
61 lines (44 loc) · 1.27 KB
/
Histograms.R
File metadata and controls
61 lines (44 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File: Histograms.R
# Course: R: An Introduction (with RStudio)
# LOAD PACKAGES ############################################
library(datasets)
# LOAD DATA ################################################
?iris
head(iris)
# BASIC HISTOGRAMS #########################################
hist(iris$Sepal.Length)
hist(iris$Sepal.Width)
hist(iris$Petal.Length)
hist(iris$Petal.Width)
# HISTOGRAM BY GROUP #######################################
# Put graphs in 3 rows and 1 column
par(mfrow = c(3, 1))
# Histograms for each species using options
hist(iris$Petal.Width [iris$Species == "setosa"],
xlim = c(0, 3),
breaks = 9,
main = "Petal Width for Setosa",
xlab = "",
col = "red")
hist(iris$Petal.Width [iris$Species == "versicolor"],
xlim = c(0, 3),
breaks = 9,
main = "Petal Width for Versicolor",
xlab = "",
col = "purple")
hist(iris$Petal.Width [iris$Species == "virginica"],
xlim = c(0, 3),
breaks = 9,
main = "Petal Width for Virginica",
xlab = "",
col = "blue")
# Restore graphic parameter
par(mfrow=c(1, 1))
# CLEAN UP #################################################
# Clear packages
detach("package:datasets", unload = TRUE) # For base
# Clear plots
dev.off() # But only if there IS a plot
# Clear console
cat("\014") # ctrl+L
# Clear mind :)