Layer Labels (Annotations) in geom_crossbar

In [1]:
from lets_plot import *
LetsPlot.setup_html()
In [2]:
data = {
    'vertical_category': ['Without midline', 'Above midline', 'Below midline', 'Above bar', 'Below bar'],
    'horisontal_category': ['Without midline', 'Right of midline', 'Left of midline', 'Right of bar', 'Left of bar'],
    'ymin': [0, 5, 5, 0, 20],
    'ymax': [20, 20, 20, 2, 22],
    'y': [None, 6, 19, 1, 21],
    'value': [20, 15, 15, 2, 2]
}

Automatic Text Positioning

In [3]:
ggplot(data) + \
    geom_crossbar(
        aes(x='vertical_category', y='y', ymin='ymin', ymax='ymax'), 
        labels=layer_labels(["value"]).size(20))
Out[3]:
In [4]:
ggplot(data) + coord_flip() + \
    geom_crossbar(
        aes(x='horisontal_category', y='y', ymin='ymin', ymax='ymax'), 
        labels=layer_labels(["value"]).size(20))
Out[4]:

Long Labels Handling

Lond text strings that don't fit in the bar are drawn with a background.

In [5]:
ggplot(data) + \
    geom_crossbar(
        aes(x='vertical_category', y='y', ymin='ymin', ymax='ymax'), 
        fill='lightblue',
        labels=layer_labels(["vertical_category"]).size(20))
Out[5]:

Inheriting the Geometry Colors

In [6]:
ggplot(data) + \
    geom_crossbar(
        aes(x='vertical_category', y='y', ymin='ymin', ymax='ymax', color="vertical_category"), 
        show_legend=False,
        labels=layer_labels(["value"])
            .size(20)
            .inherit_color()      # <--- Enable using the geometry color in labels.
    )          
Out[6]: