<jupyter_start><jupyter_text>This page is available as an executable or viewable Jupyter Notebook:<a href="https://mybinder.org/v2/gh/JetBrains/lets-plot/v1.5.2demos1?filepath=docs%2Fexamples%2Fjupyter-notebooks%2Fscatter_plot.ipynb"   target="_parent">    <img align="left"         src="https://mybinder.org/badge_logo.svg"><a href="https://nbviewer.jupyter.org/github/JetBrains/lets-plot/blob/master/docs/examples/jupyter-notebooks/scatter_plot.ipynb"    target="_parent">    <img align="right"         src="https://raw.githubusercontent.com/jupyter/design/master/logos/Badges/nbviewer_badge.png"         width="109" height="20"><jupyter_code>import numpy as np
import random
from lets_plot import *

LetsPlot.setup_html()
# This example was found at: www.cookbook-r.com/Graphs/Scatterplots_(ggplot2)
random.seed(123)
data = dict(
    cond=np.repeat(['A','B'], 10),
    xvar=[i + random.normalvariate(0, 3) for i in range(0,20)],
    yvar=[i + random.normalvariate(0, 3) for i in range(0,20)]
)<jupyter_output><empty_output><jupyter_text>Basic scatter-plot<jupyter_code>p = ggplot(data, aes(x='xvar', y='yvar')) + ggsize(300, 250)
p + geom_point(shape=1)<jupyter_output><empty_output><jupyter_text>Add regression line<jupyter_code>p + geom_point(shape=1) + geom_smooth() 
# Without standard error band.
p + geom_point(shape=1) + geom_smooth(se=False)<jupyter_output><empty_output><jupyter_text>Split dataset by the `cond` variable<jupyter_code>p1 = ggplot(data, aes(x='xvar', y='yvar', color='cond')) + ggsize(500, 250)
p1 + geom_point(shape=1) + geom_smooth(se=False)
# Map `shape` to the `cond` variable.
p2 = p1 + geom_point(aes(shape='cond'), size=5)
p2
# Choose different shapes using `scale_shape_manual`:
# 1 - hollow circle 
# 2 - hollow triangle

p2 + scale_shape_manual(values=[1,2])<jupyter_output><empty_output><jupyter_text>Handling overplotting<jupyter_code># Create data containing overlapping points.
data['xrnd'] = [round(v / 5) * 5 for v in data['xvar']]
data['yrnd'] = [round(v / 5) * 5 for v in data['yvar']]
p3 = ggplot(data, aes(x='xrnd', y='yrnd')) + ggsize(500, 250)

# Use `alpha` to show overplotting.
p3 + geom_point(alpha=.3, size=5)
# `jitter` points to show overplotting in another way.
p3 + geom_point(shape=1, position=position_jitter(width=.2,height=.5))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1591203104786546, 'fraction_numerical': 0.031910306166451054, 'mean_word_length': 6.25, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '331028', 'license': 'MIT', 'n_tokens_mistral': 963, 'n_tokens_neox': 897, 'n_words': 162, 'path': 'docs/examples/jupyter-notebooks/scatter_plot.ipynb', 'repo_name': 'OLarionova-HORIS/lets-plot', 'size': '2319'}