Frequency Polygon Plot

Want to learn more? I recommend working through: R for Data Science, R Cookbook, and R Graphics Cookbook.

# load the gcookbook package for the data
library(gcookbook)

# load the ggplot2 package
library(ggplot2)

# reset the graphing device
dev.off()
null device
          1
# divide the faithful$waiting data into 10 bins
binsize <- diff(range(faithful$waiting))/10
# create the ggplot2 data for the faithful$waiting variable
ggplot(faithful, aes(x=waiting)) +
  # add a sensity line
  geom_freqpoly(binwidth=binsize) +
  # zoom out the plot a little bit
  expand_limits(y=0)

png