r - Multiple boxplots of vector with breaks (and variable widths) -


i have vector of numeric samples. have calculated smaller vector of breaks group values. create boxplot has 1 box every interval, width of each box coming third vector, same length breaks vector.

here sample data. please note real data has thousands of samples , @ least tens of breaks:

v <- c(seq.int(5), seq.int(7) * 2, seq.int(4) * 3) v1 <- c(1, 6, 13) # breaks v2 <- c(5, 10, 2) # relative widths 

this how might make separate boxplots, ignorant of widths:

boxplot(v[v1[1]:v1[2]-1]) boxplot(v[v1[2]:v1[3]-1]) boxplot(v[v1[3]:length(v)]) 

i solution single boxplot() call without excessive data conditioning. example, putting vector in data frame , adding column region/break number seems inelegant, i'm not yet "thinking in r", perhaps best.

base r preferred, take can get.

thanks.

try this:

v1 <- c(v1, length(v) + 1) a01 <- unlist(mapply(rep, 1:(length(v1)-1), diff(v1)))  boxplot(v ~ a01, names= paste0("g", 1:(length(v1)-1))) 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -