[R] sequentially aggregating elements of a vector

Martin Batholdy batholdy at googlemail.com
Mon Oct 14 20:49:53 CEST 2013


for labelling the stacked bars in a barplot, I need to sequentially sum up the elements of a vector.

Suppose I have;

x <- c(1,2,3,4)

(which correspond to the bar-width of stacked bars)

I need;

y <- c(1,3,6,11)

(which corresponds to the upper y-values for each bar).

What is the easiest way in R to get from x to y?
(Or more general; to add labels inside the bars in a stacked barplot)


More information about the R-help mailing list