histogram | R Documentation |
histogram with overlay
histogram( num, fac, bins = 50, colours = c("red", "blue", "grey", "gold"), xlab = "", numrange = c(NA, NA) )
num |
numerical vector |
fac |
vector with factor or character |
bins |
numeric, the number of bins for the histogram |
colours |
colours to be used for categories (by default four different colours) |
xlab |
character, label for x-axis |
numrange |
numeric of length 2, range for numerical values to consider |
numrange
is by default c(NA, NA)
, which does not constrain the range along the numeric variable
a plot
xdata <- data.frame(var = NA, fac = sample(letters[1:3], size = 20000, replace = TRUE)) xdata$var[xdata$fac == "a"] <- rnorm(n = table(xdata$fac)["a"], mean = -2) xdata$var[xdata$fac == "b"] <- rnorm(n = table(xdata$fac)["b"], mean = 0) xdata$var[xdata$fac == "c"] <- rnorm(n = table(xdata$fac)["c"], mean = 1) histogram(num = xdata$var, fac = xdata$fac, bins = 10) histogram(num = xdata$var, fac = xdata$fac, bins = 50) histogram(num = xdata$var, fac = xdata$fac, bins = 100) histogram(num = xdata$var, fac = xdata$fac, bins = 50, numrange = c(-2, 2)) histogram(num = xdata$var, fac = xdata$fac, bins = 100, colours = rainbow(3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.