View source: R/Return_n_function.R
give_Qn | R Documentation |
This function returns the length (number of observations, n) of a vector and a pre-specified quartile (Q).
give_Qn(x)
x |
A numeric vector. |
Q |
The quartile (y-value) for the label (n). Q must be between 0 and 1. |
When used with ggplot, it can to place the number of observations within the box of a box-and-whisker plot
into the box at the specified Y-value quartile (Q).
Note that the parameter Q must be specified before using the function.
color.dat <- c(rep('A', 10),rep('B', 10))
y.dat <- c(rnorm(10,2, 2), rnorm(10,5,5))
example.dat <- data.frame(cbind(color.dat,as.numeric(y.dat)))
Q <- 0.75
(ggplot(example.dat, aes(y=y.dat, x=color.dat, fill=color.dat))
+ geom_boxplot(color='grey30', aes(fill=color.dat))
+ stat_summary(fun.data = give.Qn, geom = "text", position = position_dodge(width = 0.75), size = 5, color='red')
+ scale_fill_manual('', values=c("grey80","grey60"))
+ theme_bw())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.