Reputation: 299
I have plotted a boxplot
for timeseries data with freq=12 in R. I want R to display median values in boxplot
for every month. How would I do that?
R code:
st_ts = ts(stocks[,2],start = c(2000,4),end = c(2015,10),frequency = 12)
boxplot(st_ts ~ cycle(st_ts))
Upvotes: 3
Views: 1183
Reputation: 1165
Here with ggplot
library(ggplot2)
data <- data.frame(abs = as.factor(rep(1:12, 10)), ord = rnorm(120, 5, 1))
calcmed <- function(x) {
return(c(y = 8, label = round(median(x), 1)))
# modify 8 to suit your needs
}
ggplot(data, aes(abs, ord)) +
geom_boxplot() +
stat_summary(fun.data = calcmed, geom = "text") +
#annotate("text", x = 1.4, y = 8.3, label = "median :") +
xlab("Abs") +
ylab("Ord") +
ggtitle("Boxplot")
Upvotes: 3