Skip to content

Instantly share code, notes, and snippets.

@mollietaylor
Created September 23, 2012 03:17

Revisions

  1. mollietaylor created this gist Sep 23, 2012.
    46 changes: 46 additions & 0 deletions histdens2.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    png("beaverhistextra.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),
    ylim = c(0,3),
    xlab = "Temperature",
    main = "Beaver #1")
    lines(density(beaver1$temp), # density plot
    lwd = 2, # thickness of line
    col = "chocolate3")
    abline(v = mean(beaver1$temp),
    col = "royalblue",
    lwd = 2)
    abline(v = median(beaver1$temp),
    col = "red",
    lwd = 2)
    legend(x = "topright", # location of legend within plot area
    c("Density plot", "Mean", "Median"),
    col = c("chocolate3", "royalblue", "red"),
    lwd = c(2, 2, 2))
    hist(beaver2$temp, # histogram
    col = "peachpuff", # column color
    border = "black",
    prob = TRUE, # show densities instead of frequencies
    xlim = c(36,38.5),
    ylim = c(0,3),
    xlab = "Temperature",
    main = "Beaver #2")
    lines(density(beaver2$temp), # density plot
    lwd = 2, # thickness of line
    col = "chocolate3")
    abline(v = mean(beaver2$temp),
    col = "royalblue",
    lwd = 2)
    abline(v = median(beaver2$temp),
    col = "red",
    lwd = 2)
    legend(x = "topright",
    c("Density plot", "Mean", "Median"),
    col = c("chocolate3", "royalblue", "red"),
    lwd = c(2, 2, 2))
    dev.off()