import pandas as pd
from lets_plot import *
LetsPlot.setup_html()
df = {'cond': ['A', 'A', 'B', 'B', 'C', 'C'], \
'x': [2, 3, 2, 3, 2, 3], \
'y': [1.0, 1.5, 2.0, 1.0, 1.6, 1.8]}
# Let's plot default lines and points
ggplot(df) + geom_line(aes(x='x', y='y', group='cond')) + \
geom_point(aes(x='x', y='y'))
# Let's set dotted thicker line and hollow large squares
ggplot(df) + geom_line(aes(x='x', y='y', group='cond'), linetype='dotted', size = 1.5) + \
geom_point(aes(x='x', y='y'), shape = 0, size = 4)
# We can make line type and shape of points depend on variable
ggplot(df) + geom_line(aes(x='x', y='y', group='cond', linetype='cond')) + \
geom_point(aes(x='x', y='y', shape='cond'), size=4)
# The same but with hollow shapes
ggplot(df, aes(x='x', y='y', group='cond')) + \
geom_line(aes(linetype='cond')) + \
geom_point(aes(shape='cond'), size=4) + scale_shape(solid=False)
# Let's manually change the specific linetypes and shapes that are used
ggplot(df) + geom_line(aes(x='x', y='y', group='cond', linetype='cond')) + \
geom_point(aes(x='x', y='y', shape='cond'), size=4) + \
scale_linetype_manual(values=('dotdash', 'dotted', 'dashed')) + \
scale_shape_manual(values=(6, 7, 8))
# Let's set gray lines and shapes with green fill
ggplot(df, aes(x='x', y='y', group='cond')) + \
geom_line(aes(linetype='cond'), size=1.5, color='gray') + \
geom_point(aes(shape='cond'), fill='dark_green', color='gray', size=6) + \
scale_shape_manual(values=(21,22,24)) # Shapes: Filled circle, square, triangle
# We can also add alpha channel(transparency)
ggplot(df, aes(x='x', y='y', group='cond')) + \
geom_line(aes(linetype='cond'), size = 1.5, color='gray', alpha=.5) + \
geom_point(aes(shape='cond'), fill='dark_green', color='gray', size=6, alpha=.7) + \
scale_shape_manual(values=(21,22,24))