Skip to content

Instantly share code, notes, and snippets.

@mollietaylor
Created September 9, 2012 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mollietaylor/3685924 to your computer and use it in GitHub Desktop.
Save mollietaylor/3685924 to your computer and use it in GitHub Desktop.
Histogram + Density Plot Combo in R
png("beaverhist.png")
layout(matrix(c(1:2), 2, 1,
byrow = TRUE))
hist(beaver1$temp, # histogram
col = "peachpuff", # column color
border = "black",
prob = TRUE, # show densities instead of frequencies
xlim = c(36,38.5),
xlab = "temp",
main = "Beaver #1")
lines(density(beaver1$temp), # density plot
lwd = 2, # thickness of line
col = "chocolate3")
hist(beaver2$temp, # histogram
col = "peachpuff", # column color
border = "black",
prob = TRUE, # show densities instead of frequencies
xlim = c(36,38.5),
xlab = "temp",
main = "Beaver #2")
lines(density(beaver2$temp), # density plot
lwd = 2, # thickness of line
col = "chocolate3")
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment