I added an example here:
https://github.com/tidyverse/ggplot2/issues/1965
Here is it too; please compare the plots generated by 2.1.0 to those
generated by 2.2.0:
library(ggplot2)
x <- data.frame(
a=c("A", "A", "B", "B"),
b=c("x", "y", "x", "y"),
m=c(4, 8, 7, 3)
)
# Example 1: label at the top of the bar segment
ggplot(x, aes(x=a, y = m)) +
geom_bar(stat="identity", aes(fill=a, alpha=b)) +
geom_text(position = "stack", aes(label=m), vjust=-0.3, size = 3) +
scale_alpha_discrete(range=c(1, 0.5))
# Example 2: label at the center of the bar segment
x = x[order(x$a, x$b),]
x$p = ave(x$m, x$a, FUN = cumsum)
x$p = x$p - x$m * 0.5
# p is a calculated label pos for the second example such that within each x$a
# category the labels are centered for the stacked x$b;
# e.g x$p[2] = x$m[1] + x$m[2] / 2
ggplot(x, aes(x=a, y = m)) +
geom_bar(stat="identity", aes(fill=a, alpha=b)) +
geom_text(position = "identity", aes(y=p, label=m), size = 3) +
scale_alpha_discrete(range=c(1, 0.5))
At least the second example goes wrong with ggplot2 2.2.0 (can't test the
first one with 2.2.0 at the moment; will do it this evening).
Of course it is possible to calculate x$p according to the new scheme. However,
I do not think that this is intuitively, because in 2.1.0 all x$m from the first
to the current must be summed up while in 2.2.0 all x$m from the last to the
current must be regarded. This is not as easy as here, because x$b must at first
be ordered descending to calculate the label pos and after that it must be
reordered ascending to confirm to the new display behaviour of ggplot2 2.2.0.
Thank you
Michael