-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathScatterplots.R
42 lines (29 loc) · 984 Bytes
/
Scatterplots.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
# File: Scatterplots.R
# Course: R: An Introduction (with RStudio)
# LOAD DATASETS PACKAGES ###################################
library(datasets) # Load/unload base packages manually
# LOAD DATA ################################################
?mtcars
head(mtcars)
# PLOTS ####################################################
# Good to first check univariate distributions
hist(mtcars$wt)
hist(mtcars$mpg)
# Basic X-Y plot for two quantitative variables
plot(mtcars$wt, mtcars$mpg)
# Add some options
plot(mtcars$wt, mtcars$mpg,
pch = 19, # Solid circle
cex = 1.5, # Make 150% size
col = "#cc0000", # Red
main = "MPG as a Function of Weight of Cars",
xlab = "Weight (in 1000 pounds)",
ylab = "MPG")
# 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 :)