Figure A2-1: Default Histograms

Portfolio Categories: All Graphics and SGR Book Graphics.

A Simple Default Histogram with R Graphics

A Simple Default Histogram


TG = ToothGrowth                       # Shorten dataset name
TG$supp2 = as.character(TG$supp)       # Add character version of supp

# Appendix II.2 - Visualizing univariate data ============================ AII.2

# histograms -------------------------------------------------------------------

png(filename = "illustrations/fig-AII-1-univariate visualization 1.png",
  units = "in",                        # Set measurements in inches
  res = 1200,                          # Set resolution at 1200dpi
  width = 6,                           # Width at 6 inches
  height = 4)                          # Height at 4 inches

par(mfrow=c(1, 2),                     # Set multiple plots
  mai = c(.85, .85, .5, .25))          # Set margins
hist(TG$len)                           # Default histogram: numeric var
hist(TG$len, breaks = 4)               # Histogram w/ about 4 breaks

dev.off()                              # Output png file