Piotr Bialas  Introductory Statistics with R

  • Welcome
  • Histogram 1
    • Histogram 2
    • How to Create a Histogram in R?
    • Histogram 3
  • Chapter 0
    • Chapter 1
    • Chapter 2.1
    • Chapter 2.2
    • Chapter 2.3
    • Chapter 2.4
  • Assignments
    • Extra Credit 1
  • Binomial Distr.
  • StandardND
  • Welcome
  • Histogram 1
    • Histogram 2
    • How to Create a Histogram in R?
    • Histogram 3
  • Chapter 0
    • Chapter 1
    • Chapter 2.1
    • Chapter 2.2
    • Chapter 2.3
    • Chapter 2.4
  • Assignments
    • Extra Credit 1
  • Binomial Distr.
  • StandardND

Chapter 2.1

How to Create Basic Plots in R?

Histogram of Frequency Distribution (What do we need to constract a histogram?)

  1. Data set/single quantitative variable entered by hand or uploaded
  2. Arbitrary bins/class intervals
  3. Scales for x-axis and y-axis
  4. Labels for: x-axis and y-axis
  5. Frequency Table-OPTIONAL, (e.g. useful in graphing relative frequency histogram)
  6. Title/subtitle
  7. 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")

Powered by Create your own unique website with customizable templates.