r - ggplot: plot geom_boxplot from list of elements of different length -


i have timeseries of elements grouped in list of length t.

series <- seq(1:10)  lst <- list()  set.seed(28100) (t in series) {   lst[[t]] <- sample(c(1:20, na), sample(1:20, 1)) } 

the length of list elements can vary; it's not feasible create a two-dimensions data.frame list:

lst # [[1]] # [1]  6  7 12  4 15 20  3 #  # [[2]] # [1] 14 18  8 20 na  6 19  4  9  5  1 13  3 10 12 15 # [17] 11 17 #  # ... #  # [[9]] # [1]  3  9 12  8 16 15 10 19 14 11  6  2 20 13  5 18 #  # [[10]] # [1]  4 20 10  2 12  5 19  1 na 11 14  7 17 

i still want create timeseries boxplot (such this) geom_boxplot() including outliers of distributions.

if trying plot series on x-axis , sampled values (i'll call them y) on y-axis, create list of data frames , stack them data structure ggplot needs. example:

library(ggplot2)  # modify lst data frames of varying dimension lst <- lapply(series, function(x) {   data.frame(series = factor(x, levels = series),              y = lst[[x]]) })  # stack data frames lst <- do.call(rbind, lst)  # make plot ggplot(lst, aes(x = series, y = y)) +   geom_boxplot() 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -