-
Notifications
You must be signed in to change notification settings - Fork 10
/
BarCharts.R
36 lines (23 loc) · 826 Bytes
/
BarCharts.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
# File: BarCharts.R
# Course: R: An Introduction (with RStudio)
# LOAD DATASETS PACKAGES ###################################
library(datasets)
# LOAD DATA ################################################
?mtcars
head(mtcars)
# BAR CHARTS ###############################################
barplot(mtcars$cyl) # Doesn't work
# Need a table with frequencies for each category
cylinders <- table(mtcars$cyl) # Create table
barplot(cylinders) # Bar chart
plot(cylinders) # Default X-Y plot (lines)
# CLEAN UP #################################################
# Clear environment
rm(list = ls())
# 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 :)