# Simple example
x <- c(1, 1, 2, 2, 2, 5, 5)
plot_freq(x)
# Pass on some common \code{plot()} arguments
plot_freq(x, col = "steelblue", xlab = "Value", ylab = "Frequency",ylim=c(0,7))
# Add to an existing plot
plot_freq(x, col = "dodgerblue")
plot_freq(x + 1, col = "red", add = TRUE)
# Compare two vectors
y1 <- c(1, 1, 2, 2, 2, 5, 5)
y2 <- c(1, 2, 2, 3, 3, 3)
plot_freq(y1, y2)
# Compare two vectors with custom labels
plot_freq(y1, y2, labels = c("men", "women"))
# Using a data frame with grouping
df <- data.frame(value = c(1, 1, 2, 2, 2, 5, 5), group = c("A", "A", "A", "B", "B", "A", "B"))
plot_freq(value ~ 1, data = df) # single variable
plot_freq(value ~ group, data = df) # with grouping
# Control group order in legend and plot
plot_freq(value ~ group, data = df, order = c("B", "A")) # B first, then A
plot_freq(value ~ group, data = df, order = -1) # Reverse default order
Run the code above in your browser using DataLab