Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

6. Summarized Data Distributions > Making a Basic Histogram

Making a Basic Histogram

Problem

You want to make a histogram.

Solution

Use geom_histogram() and map a continuous variable to x (Figure 6-1):

ggplot(faithful, aes(x=waiting)) + geom_histogram()
A basic histogram
Figure 6-1. A basic histogram

Discussion

All geom_histogram() requires is one column from a data frame or a single vector of data. For this example we’ll use the faithful data set, which contains data about the Old Faithful geyser in two columns: eruptions, which is the length of each eruption, and waiting, which is the length of time to the next eruption. We’ll only use the waiting column in this example:

faithful

eruptions waiting
    3.600      79
    1.800      54
    3.333      74
...

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint