-
Notifications
You must be signed in to change notification settings - Fork 10
/
Plot.R
55 lines (39 loc) · 1.32 KB
/
Plot.R
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
# File: Plot.R
# Course: R: An Introduction (with RStudio)
# LOAD DATASETS PACKAGES ###################################
library(datasets) # Load/unload base packages manually
# LOAD DATA ################################################
head(iris)
# PLOT DATA WITH PLOT() ####################################
?plot # Help for plot()
plot(iris$Species) # Categorical variable
plot(iris$Petal.Length) # Quantitative variable
plot(iris$Species, iris$Petal.Width) # Cat x quant
plot(iris$Petal.Length, iris$Petal.Width) # Quant pair
plot(iris) # Entire data frame
# Plot with options
plot(iris$Petal.Length, iris$Petal.Width,
col = "#cc0000", # Hex code for datalab.cc red
pch = 19, # Use solid circles for points
main = "Iris: Petal Length vs. Petal Width",
xlab = "Petal Length",
ylab = "Petal Width")
# PLOT FORMULAS WITH PLOT() ################################
plot(cos, 0, 2*pi)
plot(exp, 1, 5)
plot(dnorm, -3, +3)
# Formula plot with options
plot(dnorm, -3, +3,
col = "#cc0000",
lwd = 5,
main = "Standard Normal Distribution",
xlab = "z-scores",
ylab = "Density")
# CLEAN UP #################################################
# Clear packages
detach("package:datasets", unload = TRUE)
# Clear plots
dev.off() # But only if there IS a plot
# Clear console
cat("\014") # ctrl+L
# Clear mind :)