Chapter 2.1
How to Create Basic Plots in R?
Histogram of Frequency Distribution (What do we need to constract a histogram?)
- Data set/single quantitative variable entered by hand or uploaded
- Arbitrary bins/class intervals
- Scales for x-axis and y-axis
- Labels for: x-axis and y-axis
- Frequency Table-OPTIONAL, (e.g. useful in graphing relative frequency histogram)
- Title/subtitle
- Optional: colors for bars, border for bars, …
Example 1 (Artificial single-variable data entered by hand: number of states visited)
states <-c(12,3,4,4,3,7,3,3,4,4,4,5,5,5,5,5,1,2,2,6,6,6,7,7,7,8,8,8,9,9,10,10,10,11,12);states
## [1] 12 3 4 4 3 7 3 3 4 4 4 5 5 5 5 5 1 2 2 6 6 6 7
## [24] 7 7 8 8 8 9 9 10 10 10 11 12
Using the syntax below
hist(states)
you have constructed a histogram excercising no control over its appearance.
Let’s improve appearance of your histogram by using additional arguments.
hist(states, breaks = seq(1, 12, by = 1), xlim=c(0,12), ylim=c(0,10), xlab="Number of States visited",ylab="Frequency",main="Distribution of Number of States Visited",col ="yellow",border="blue")