<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-kotlin/v1.0.0demos1?filepath=docs%2Fexamples%2Fjupyter-notebooks%2Flegend_and_axis.ipynb"   target="_parent">   <img align="left"        src="https://mybinder.org/badge_logo.svg"><a href="https://nbviewer.jupyter.org/github/JetBrains/lets-plot-kotlin/blob/master/docs/examples/jupyter-notebooks/legend_and_axis.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>%use lets-plot
%use krangl
val mpg_df = DataFrame.readCSV("https://jetbrains.bintray.com/lets-plot/mpg.csv")
mpg_df.head()
// val mpg = mpg_df.names.map {Pair(it, mpg_df[it].values())}.toMap()
val mpg = mpg_df.toMap()
// Default legend
val p = lets_plot(mpg) {x="displ"; y="hwy"; color="manufacturer"} + geom_point(size=5.0) + ggsize(500,250)
p
// Layout the legend in two columns
p + scale_color_discrete(guide=guide_legend(ncol=2)) + ggtitle("Two columns legend")
// Same and fill by rows
p + scale_color_discrete(guide=guide_legend(ncol=2, byRow=true)) +
ggtitle("Two columns legend filled by rows")
// Adjust legend and axis
//  - five rows legend
//  - draw legend below plot
//  - remove axis
p + scale_color_discrete(guide=guide_legend(nrow=5)) +
    theme().legendPosition_bottom().axisLine_blank().axisTitle_blank() +
    ggtitle("Five rows legend and below") + ggsize(500,400)
// Set color to city MPG and shape to drive·train
val p1 = ggplot(mpg) {x="displ"; y="hwy"} + geom_point(size=5.0) {color="cty"; shape="drv"} + ggsize(700, 350)
p1
// Change legend position and orientation
p1 + theme().legendPosition(1, 1).legendJustification(1, 1).legendDirection_horizontal()
// Adjust colorbar size
// Change order in drive-train legend
// Set labels to legends and axis
// Remove vertical axis line
p1 + theme().legendPosition(1, 1).legendJustification(1, 1).legendDirection_horizontal().axisLineY_blank() +
    scale_color_continuous(name="City MPG", 
                           low="dark_blue", high="light_blue", 
                           guide=guide_colorbar(barHeight=10, barWidth=300)) +
    scale_shape(name="Drive-train", breaks=listOf('f', 'r', '4'), labels=listOf("front", "rear", "4X4")) +
    xlab("Engine displacement (L)") + ylab("Highway MPG")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1558811558811559, 'fraction_numerical': 0.023606023606023607, 'mean_word_length': 4.838479809976247, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '627977', 'license': 'MIT', 'n_tokens_mistral': 928, 'n_tokens_neox': 866, 'n_words': 165, 'path': 'docs/examples/jupyter-notebooks/legend_and_axis.ipynb', 'repo_name': 'OLarionova-HORIS/lets-plot-kotlin', 'size': '2457'}