Histogram with Density Trace

It’s easy to create a histogram with a density trace in R using base commands.

  htwt <- read.csv("http://facweb1.redlands.edu/fac/jim_bentley/downloads/math111/htwt.csv")
  htwt$Group = factor(htwt$Group, levels=c(1,2), labels=c("Male","Female"))
  hist(htwt$Weight, prob=TRUE)
  lines(density(htwt$Weight))

Violin Plots

GGPLOT2 makes it easy to create violin plots.

 p_load(ggplot2)
 ggplot(htwt, aes(Group, Weight)) + geom_violin(trim=TRUE) + geom_boxplot(width=0.05)