In [1]:
from lets_plot import *
In [2]:
LetsPlot.setup_html()
In [3]:
def plot1(position=None):
    data = {'x': [0, 0], 'y': [0, 0], 'g': ['a', 'b']}
    return ggplot(data, aes('x', 'y', color='g')) + \
        geom_point(position=position) + \
        ggtitle("position={0}".format(str(position).replace("\n", "")))

gggrid([
    plot1(),
    plot1("dodge"),
    plot1(position_dodge()),
    plot1(position_dodge(width=1.5)),
], ncol=2)
Out[3]:
In [4]:
def plot2(position=None):
    data = {
        'x': ['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b'],
        'y': [0, 1, -1, 0, -1, 2, -2, 1],
        'g': ['x', 'x', 'y', 'y', 'x', 'x', 'y', 'y']
    }
    return ggplot(data, aes('x', 'y', color='g')) + \
        geom_boxplot(position=position) + \
        ggtitle("position={0}".format(str(position).replace("\n", "")))

gggrid([
    plot2(),
    plot2("dodge"),
    plot2(position_dodge()),
    plot2(position_dodge(width=1.5)),
    plot2("jitter"),
    plot2(position_jitter()),
    plot2(position_jitter(width=2, height=10)),
], ncol=2)
Out[4]:
In [5]:
def plot3(*, width=None, height=None, position=None):
    data = {'x': [0] * 5000, 'y': [0] * 5000}
    return ggplot(data, aes('x', 'y')) + \
        geom_jitter(width=width, height=height, position=position) + \
        ggtitle("width={0}, height={1},\nposition={2}".format(width, height, str(position).replace("\n", "")))

gggrid([
    plot3(),
    plot3(width=2, height=1),
    plot3(position=position_jitter(width=4, height=2)),
    plot3(width=2, height=1, position=position_jitter(width=4, height=2)),
    plot3(width=2, position=position_jitter(height=2)),
], ncol=2)
Out[5]:
In [6]:
def plot4(stackgroups=None):
    data = {
        'x': ['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b'],
        'y': [0, 1, -1, 0, -1, 2, -2, 1],
        'g': ['x', 'x', 'y', 'y', 'x', 'x', 'y', 'y']
    }
    return ggplot(data, aes('x', 'y', fill='g')) + \
        geom_ydotplot(stackgroups=stackgroups, dotsize=5, alpha=.5) + \
        ggtitle("stackgroups={0}".format(stackgroups))

gggrid([
    plot4(False),
    plot4(True),
])
Out[6]:
In [7]:
def plot5(*, nudge_x=None, nudge_y=None, position=None):
    data = {'x': [0, 0], 'y': [0, 0], 'g': ['a', 'b']}
    return ggplot(data, aes('x', 'y', color='g')) + \
        geom_point(size=40, alpha=.2) + \
        geom_text(aes(label='g'), nudge_x=nudge_x, nudge_y=nudge_y, position=position, \
                  size=20, show_legend=False) + \
        ggtitle("nudge_x={0}, nudge_y={1},\nposition={2}".format(nudge_x, nudge_y, str(position).replace("\n", "")))

gggrid([
    plot5(),
    plot5(nudge_x=.2),
    plot5(nudge_x=.2, position='identity'),
    plot5(nudge_x=.2, position=position_nudge(x=.4)),
    plot5(nudge_x=.2, position=position_nudge(y=.2)),
    plot5(position='dodge'),
    plot5(nudge_x=.2, position='dodge'),
    plot5(nudge_y=.2, position='dodge'),
], ncol=2)
Out[7]: