In [1]:
from lets_plot import *

LetsPlot.setup_html()
In [2]:
data = {
    'x': [1, 1, 2, 2, 2],
    'y' : [1, 3, 2, 1, -3],
    'grp': ["a", "b", "a", "b", "c"]
}

p = ggplot(data, aes('x', 'y', group = 'grp')) + \
    geom_bar(aes(fill = 'grp'), stat = 'identity', color = 'black') + \
    scale_fill_brewer(palette = "Pastel1")
In [3]:
w, h = 600, 400

bunch = GGBunch()
bunch.add_plot(p + geom_label(aes(label = 'y'), position = 'stack') + ggtitle("Default"), 0, 0)
bunch.add_plot(p + geom_label(aes(label = 'y'), position = position_stack(0.0)) + ggtitle("vjust = 0.0"), w, 0)
bunch.add_plot(p + geom_label(aes(label = 'y'), position = position_stack(0.3)) + ggtitle("vjust = 0.3"), 0, h)
bunch.add_plot(p + geom_label(aes(label = 'y'), position = position_stack(0.5)) + ggtitle("vjust = 0.5"), w, h)
bunch.add_plot(p + geom_label(aes(label = 'y'), position = position_stack(0.7)) + ggtitle("vjust = 0.7"), 0, 2*h)
bunch.add_plot(p + geom_label(aes(label = 'y'), position = position_stack(1.0)) + ggtitle("vjust = 1.0"), w, 2*h)
bunch.show()
In [4]:
# position = 'fill' 

p2 = ggplot(data, aes('x', 'y', group = 'grp')) + \
     geom_bar(aes(fill = 'grp'), stat = 'identity', position = 'fill', color = 'black') + \
     scale_fill_brewer(palette = "Pastel1")

p2 + geom_text(aes(label = 'y'), position = position_fill(0.5))
Out[4]:
In [5]:
import numpy as np

series = {
  'x':  [1]*4 + [2] * 4 + [3] * 4 + [4] * 4,
  'type': ['a', 'b', 'c', 'd'] * 4,
  'value': np.random.poisson(100, size=16)
}
p3 = ggplot(series, aes('x', 'value', group = 'type')) + geom_area(aes(fill = 'type'), color = 'white') 
p3
Out[5]:
In [6]:
# vjust=0.5 will center the labels inside the corresponding area
p3 + geom_label(aes(label = 'type'), position = position_stack(vjust = 0.5)) 
Out[6]: