Professional Documents
Culture Documents
Let’s look at how we can use R to construct a histogram. I have opened RStudio
and have prepared a script for us to use. Histograms are for use with quantitative
data. I have been analyzing data from the Titanic disaster, so continuing with that
dataset, let’s look at the distribution of passenger ages.
As always, I need to make sure that my data are read into an R object, so I’ll do
that now.
Speaking of titles, let’s give this graph a title using the argument “main.” Sensibly
enough, I titled this, “ages of passengers on the Titanic.”
Let’s make sure that our files and plots pane is a good size for displaying this
graph, then run the hist function.
Here’s the histogram. The mode is in the low 20s. There are some children on
board, but not too many people in their 70s and 80s, so that the distribution has a
slight positive skew.
1
This graph is now ready to export for use in a report of our data analysis. Pretty
simple, isn’t it? Go give it a try!