{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Wizualizacja danych (Lab 3)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "library(repr) # To resize plots in Jupyter\n", "options(repr.plot.width = 16, repr.plot.height = 9)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Biblioteka plotly" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pakiet *plotly* jest pakietem graficznym, który umożliwia tworzenie interaktywnych wykresów. Cała biblioteka jest napisana w JavaScript i dostępna również dla Pythona. Składania i pomysł na tworzenie grafiki są bardzo podobne do *ggplot2*.\n", "\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Karta pomocy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " \n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Konwersja grafiki ggplot2 na plotly" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Warning message:\n", "“package ‘plotly’ was built under R version 3.6.2”\n", "Loading required package: ggplot2\n", "\n", "Warning message:\n", "“package ‘ggplot2’ was built under R version 3.6.2”\n", "\n", "Attaching package: ‘plotly’\n", "\n", "\n", "The following object is masked from ‘package:ggplot2’:\n", "\n", " last_plot\n", "\n", "\n", "The following object is masked from ‘package:stats’:\n", "\n", " filter\n", "\n", "\n", "The following object is masked from ‘package:graphics’:\n", "\n", " layout\n", "\n", "\n", "Warning message:\n", "“package ‘dplyr’ was built under R version 3.6.2”\n", "\n", "Attaching package: ‘dplyr’\n", "\n", "\n", "The following objects are masked from ‘package:stats’:\n", "\n", " filter, lag\n", "\n", "\n", "The following objects are masked from ‘package:base’:\n", "\n", " intersect, setdiff, setequal, union\n", "\n", "\n" ] } ], "source": [ "library(plotly)\n", "library(ggplot2)\n", "library(dplyr)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "attrs": { "d5c2f434d99": { "colour": {}, "type": "scatter", "x": {}, "y": {} } }, "base_url": "https://plot.ly", "config": { "doubleClick": "reset", "showSendToCloud": false }, "cur_data": "d5c2f434d99", "data": [ { "hoverinfo": "text", "hoveron": "points", "legendgroup": "setosa", "marker": { "autocolorscale": false, "color": "rgba(248,118,109,1)", "line": { "color": "rgba(248,118,109,1)", "width": 1.8898 }, "opacity": 0.8, "size": 5.6693, "symbol": "circle" }, "mode": "markers", "name": "setosa", "showlegend": true, "text": [ "Sepal.Length: 5.1
Sepal.Width: 3.5
Species: setosa", "Sepal.Length: 4.9
Sepal.Width: 3.0
Species: setosa", "Sepal.Length: 4.7
Sepal.Width: 3.2
Species: setosa", "Sepal.Length: 4.6
Sepal.Width: 3.1
Species: setosa", "Sepal.Length: 5.0
Sepal.Width: 3.6
Species: setosa", "Sepal.Length: 5.4
Sepal.Width: 3.9
Species: setosa", "Sepal.Length: 4.6
Sepal.Width: 3.4
Species: setosa", "Sepal.Length: 5.0
Sepal.Width: 3.4
Species: setosa", "Sepal.Length: 4.4
Sepal.Width: 2.9
Species: setosa", "Sepal.Length: 4.9
Sepal.Width: 3.1
Species: setosa", "Sepal.Length: 5.4
Sepal.Width: 3.7
Species: setosa", "Sepal.Length: 4.8
Sepal.Width: 3.4
Species: setosa", "Sepal.Length: 4.8
Sepal.Width: 3.0
Species: setosa", "Sepal.Length: 4.3
Sepal.Width: 3.0
Species: setosa", "Sepal.Length: 5.8
Sepal.Width: 4.0
Species: setosa", "Sepal.Length: 5.7
Sepal.Width: 4.4
Species: setosa", "Sepal.Length: 5.4
Sepal.Width: 3.9
Species: setosa", "Sepal.Length: 5.1
Sepal.Width: 3.5
Species: setosa", "Sepal.Length: 5.7
Sepal.Width: 3.8
Species: setosa", "Sepal.Length: 5.1
Sepal.Width: 3.8
Species: setosa", "Sepal.Length: 5.4
Sepal.Width: 3.4
Species: setosa", "Sepal.Length: 5.1
Sepal.Width: 3.7
Species: setosa", "Sepal.Length: 4.6
Sepal.Width: 3.6
Species: setosa", "Sepal.Length: 5.1
Sepal.Width: 3.3
Species: setosa", "Sepal.Length: 4.8
Sepal.Width: 3.4
Species: setosa", "Sepal.Length: 5.0
Sepal.Width: 3.0
Species: setosa", "Sepal.Length: 5.0
Sepal.Width: 3.4
Species: setosa", "Sepal.Length: 5.2
Sepal.Width: 3.5
Species: setosa", "Sepal.Length: 5.2
Sepal.Width: 3.4
Species: setosa", "Sepal.Length: 4.7
Sepal.Width: 3.2
Species: setosa", "Sepal.Length: 4.8
Sepal.Width: 3.1
Species: setosa", "Sepal.Length: 5.4
Sepal.Width: 3.4
Species: setosa", "Sepal.Length: 5.2
Sepal.Width: 4.1
Species: setosa", "Sepal.Length: 5.5
Sepal.Width: 4.2
Species: setosa", "Sepal.Length: 4.9
Sepal.Width: 3.1
Species: setosa", "Sepal.Length: 5.0
Sepal.Width: 3.2
Species: setosa", "Sepal.Length: 5.5
Sepal.Width: 3.5
Species: setosa", "Sepal.Length: 4.9
Sepal.Width: 3.6
Species: setosa", "Sepal.Length: 4.4
Sepal.Width: 3.0
Species: setosa", "Sepal.Length: 5.1
Sepal.Width: 3.4
Species: setosa", "Sepal.Length: 5.0
Sepal.Width: 3.5
Species: setosa", "Sepal.Length: 4.5
Sepal.Width: 2.3
Species: setosa", "Sepal.Length: 4.4
Sepal.Width: 3.2
Species: setosa", "Sepal.Length: 5.0
Sepal.Width: 3.5
Species: setosa", "Sepal.Length: 5.1
Sepal.Width: 3.8
Species: setosa", "Sepal.Length: 4.8
Sepal.Width: 3.0
Species: setosa", "Sepal.Length: 5.1
Sepal.Width: 3.8
Species: setosa", "Sepal.Length: 4.6
Sepal.Width: 3.2
Species: setosa", "Sepal.Length: 5.3
Sepal.Width: 3.7
Species: setosa", "Sepal.Length: 5.0
Sepal.Width: 3.3
Species: setosa" ], "type": "scatter", "x": [ 5.1, 4.9, 4.7, 4.6, 5, 5.4, 4.6, 5, 4.4, 4.9, 5.4, 4.8, 4.8, 4.3, 5.8, 5.7, 5.4, 5.1, 5.7, 5.1, 5.4, 5.1, 4.6, 5.1, 4.8, 5, 5, 5.2, 5.2, 4.7, 4.8, 5.4, 5.2, 5.5, 4.9, 5, 5.5, 4.9, 4.4, 5.1, 5, 4.5, 4.4, 5, 5.1, 4.8, 5.1, 4.6, 5.3, 5 ], "xaxis": "x", "y": [ 3.5, 3, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3.4, 3, 3, 4, 4.4, 3.9, 3.5, 3.8, 3.8, 3.4, 3.7, 3.6, 3.3, 3.4, 3, 3.4, 3.5, 3.4, 3.2, 3.1, 3.4, 4.1, 4.2, 3.1, 3.2, 3.5, 3.6, 3, 3.4, 3.5, 2.3, 3.2, 3.5, 3.8, 3, 3.8, 3.2, 3.7, 3.3 ], "yaxis": "y" }, { "hoverinfo": "text", "hoveron": "points", "legendgroup": "versicolor", "marker": { "autocolorscale": false, "color": "rgba(0,186,56,1)", "line": { "color": "rgba(0,186,56,1)", "width": 1.8898 }, "opacity": 0.8, "size": 5.6693, "symbol": "circle" }, "mode": "markers", "name": "versicolor", "showlegend": true, "text": [ "Sepal.Length: 7.0
Sepal.Width: 3.2
Species: versicolor", "Sepal.Length: 6.4
Sepal.Width: 3.2
Species: versicolor", "Sepal.Length: 6.9
Sepal.Width: 3.1
Species: versicolor", "Sepal.Length: 5.5
Sepal.Width: 2.3
Species: versicolor", "Sepal.Length: 6.5
Sepal.Width: 2.8
Species: versicolor", "Sepal.Length: 5.7
Sepal.Width: 2.8
Species: versicolor", "Sepal.Length: 6.3
Sepal.Width: 3.3
Species: versicolor", "Sepal.Length: 4.9
Sepal.Width: 2.4
Species: versicolor", "Sepal.Length: 6.6
Sepal.Width: 2.9
Species: versicolor", "Sepal.Length: 5.2
Sepal.Width: 2.7
Species: versicolor", "Sepal.Length: 5.0
Sepal.Width: 2.0
Species: versicolor", "Sepal.Length: 5.9
Sepal.Width: 3.0
Species: versicolor", "Sepal.Length: 6.0
Sepal.Width: 2.2
Species: versicolor", "Sepal.Length: 6.1
Sepal.Width: 2.9
Species: versicolor", "Sepal.Length: 5.6
Sepal.Width: 2.9
Species: versicolor", "Sepal.Length: 6.7
Sepal.Width: 3.1
Species: versicolor", "Sepal.Length: 5.6
Sepal.Width: 3.0
Species: versicolor", "Sepal.Length: 5.8
Sepal.Width: 2.7
Species: versicolor", "Sepal.Length: 6.2
Sepal.Width: 2.2
Species: versicolor", "Sepal.Length: 5.6
Sepal.Width: 2.5
Species: versicolor", "Sepal.Length: 5.9
Sepal.Width: 3.2
Species: versicolor", "Sepal.Length: 6.1
Sepal.Width: 2.8
Species: versicolor", "Sepal.Length: 6.3
Sepal.Width: 2.5
Species: versicolor", "Sepal.Length: 6.1
Sepal.Width: 2.8
Species: versicolor", "Sepal.Length: 6.4
Sepal.Width: 2.9
Species: versicolor", "Sepal.Length: 6.6
Sepal.Width: 3.0
Species: versicolor", "Sepal.Length: 6.8
Sepal.Width: 2.8
Species: versicolor", "Sepal.Length: 6.7
Sepal.Width: 3.0
Species: versicolor", "Sepal.Length: 6.0
Sepal.Width: 2.9
Species: versicolor", "Sepal.Length: 5.7
Sepal.Width: 2.6
Species: versicolor", "Sepal.Length: 5.5
Sepal.Width: 2.4
Species: versicolor", "Sepal.Length: 5.5
Sepal.Width: 2.4
Species: versicolor", "Sepal.Length: 5.8
Sepal.Width: 2.7
Species: versicolor", "Sepal.Length: 6.0
Sepal.Width: 2.7
Species: versicolor", "Sepal.Length: 5.4
Sepal.Width: 3.0
Species: versicolor", "Sepal.Length: 6.0
Sepal.Width: 3.4
Species: versicolor", "Sepal.Length: 6.7
Sepal.Width: 3.1
Species: versicolor", "Sepal.Length: 6.3
Sepal.Width: 2.3
Species: versicolor", "Sepal.Length: 5.6
Sepal.Width: 3.0
Species: versicolor", "Sepal.Length: 5.5
Sepal.Width: 2.5
Species: versicolor", "Sepal.Length: 5.5
Sepal.Width: 2.6
Species: versicolor", "Sepal.Length: 6.1
Sepal.Width: 3.0
Species: versicolor", "Sepal.Length: 5.8
Sepal.Width: 2.6
Species: versicolor", "Sepal.Length: 5.0
Sepal.Width: 2.3
Species: versicolor", "Sepal.Length: 5.6
Sepal.Width: 2.7
Species: versicolor", "Sepal.Length: 5.7
Sepal.Width: 3.0
Species: versicolor", "Sepal.Length: 5.7
Sepal.Width: 2.9
Species: versicolor", "Sepal.Length: 6.2
Sepal.Width: 2.9
Species: versicolor", "Sepal.Length: 5.1
Sepal.Width: 2.5
Species: versicolor", "Sepal.Length: 5.7
Sepal.Width: 2.8
Species: versicolor" ], "type": "scatter", "x": [ 7, 6.4, 6.9, 5.5, 6.5, 5.7, 6.3, 4.9, 6.6, 5.2, 5, 5.9, 6, 6.1, 5.6, 6.7, 5.6, 5.8, 6.2, 5.6, 5.9, 6.1, 6.3, 6.1, 6.4, 6.6, 6.8, 6.7, 6, 5.7, 5.5, 5.5, 5.8, 6, 5.4, 6, 6.7, 6.3, 5.6, 5.5, 5.5, 6.1, 5.8, 5, 5.6, 5.7, 5.7, 6.2, 5.1, 5.7 ], "xaxis": "x", "y": [ 3.2, 3.2, 3.1, 2.3, 2.8, 2.8, 3.3, 2.4, 2.9, 2.7, 2, 3, 2.2, 2.9, 2.9, 3.1, 3, 2.7, 2.2, 2.5, 3.2, 2.8, 2.5, 2.8, 2.9, 3, 2.8, 3, 2.9, 2.6, 2.4, 2.4, 2.7, 2.7, 3, 3.4, 3.1, 2.3, 3, 2.5, 2.6, 3, 2.6, 2.3, 2.7, 3, 2.9, 2.9, 2.5, 2.8 ], "yaxis": "y" }, { "hoverinfo": "text", "hoveron": "points", "legendgroup": "virginica", "marker": { "autocolorscale": false, "color": "rgba(97,156,255,1)", "line": { "color": "rgba(97,156,255,1)", "width": 1.8898 }, "opacity": 0.8, "size": 5.6693, "symbol": "circle" }, "mode": "markers", "name": "virginica", "showlegend": true, "text": [ "Sepal.Length: 6.3
Sepal.Width: 3.3
Species: virginica", "Sepal.Length: 5.8
Sepal.Width: 2.7
Species: virginica", "Sepal.Length: 7.1
Sepal.Width: 3.0
Species: virginica", "Sepal.Length: 6.3
Sepal.Width: 2.9
Species: virginica", "Sepal.Length: 6.5
Sepal.Width: 3.0
Species: virginica", "Sepal.Length: 7.6
Sepal.Width: 3.0
Species: virginica", "Sepal.Length: 4.9
Sepal.Width: 2.5
Species: virginica", "Sepal.Length: 7.3
Sepal.Width: 2.9
Species: virginica", "Sepal.Length: 6.7
Sepal.Width: 2.5
Species: virginica", "Sepal.Length: 7.2
Sepal.Width: 3.6
Species: virginica", "Sepal.Length: 6.5
Sepal.Width: 3.2
Species: virginica", "Sepal.Length: 6.4
Sepal.Width: 2.7
Species: virginica", "Sepal.Length: 6.8
Sepal.Width: 3.0
Species: virginica", "Sepal.Length: 5.7
Sepal.Width: 2.5
Species: virginica", "Sepal.Length: 5.8
Sepal.Width: 2.8
Species: virginica", "Sepal.Length: 6.4
Sepal.Width: 3.2
Species: virginica", "Sepal.Length: 6.5
Sepal.Width: 3.0
Species: virginica", "Sepal.Length: 7.7
Sepal.Width: 3.8
Species: virginica", "Sepal.Length: 7.7
Sepal.Width: 2.6
Species: virginica", "Sepal.Length: 6.0
Sepal.Width: 2.2
Species: virginica", "Sepal.Length: 6.9
Sepal.Width: 3.2
Species: virginica", "Sepal.Length: 5.6
Sepal.Width: 2.8
Species: virginica", "Sepal.Length: 7.7
Sepal.Width: 2.8
Species: virginica", "Sepal.Length: 6.3
Sepal.Width: 2.7
Species: virginica", "Sepal.Length: 6.7
Sepal.Width: 3.3
Species: virginica", "Sepal.Length: 7.2
Sepal.Width: 3.2
Species: virginica", "Sepal.Length: 6.2
Sepal.Width: 2.8
Species: virginica", "Sepal.Length: 6.1
Sepal.Width: 3.0
Species: virginica", "Sepal.Length: 6.4
Sepal.Width: 2.8
Species: virginica", "Sepal.Length: 7.2
Sepal.Width: 3.0
Species: virginica", "Sepal.Length: 7.4
Sepal.Width: 2.8
Species: virginica", "Sepal.Length: 7.9
Sepal.Width: 3.8
Species: virginica", "Sepal.Length: 6.4
Sepal.Width: 2.8
Species: virginica", "Sepal.Length: 6.3
Sepal.Width: 2.8
Species: virginica", "Sepal.Length: 6.1
Sepal.Width: 2.6
Species: virginica", "Sepal.Length: 7.7
Sepal.Width: 3.0
Species: virginica", "Sepal.Length: 6.3
Sepal.Width: 3.4
Species: virginica", "Sepal.Length: 6.4
Sepal.Width: 3.1
Species: virginica", "Sepal.Length: 6.0
Sepal.Width: 3.0
Species: virginica", "Sepal.Length: 6.9
Sepal.Width: 3.1
Species: virginica", "Sepal.Length: 6.7
Sepal.Width: 3.1
Species: virginica", "Sepal.Length: 6.9
Sepal.Width: 3.1
Species: virginica", "Sepal.Length: 5.8
Sepal.Width: 2.7
Species: virginica", "Sepal.Length: 6.8
Sepal.Width: 3.2
Species: virginica", "Sepal.Length: 6.7
Sepal.Width: 3.3
Species: virginica", "Sepal.Length: 6.7
Sepal.Width: 3.0
Species: virginica", "Sepal.Length: 6.3
Sepal.Width: 2.5
Species: virginica", "Sepal.Length: 6.5
Sepal.Width: 3.0
Species: virginica", "Sepal.Length: 6.2
Sepal.Width: 3.4
Species: virginica", "Sepal.Length: 5.9
Sepal.Width: 3.0
Species: virginica" ], "type": "scatter", "x": [ 6.3, 5.8, 7.1, 6.3, 6.5, 7.6, 4.9, 7.3, 6.7, 7.2, 6.5, 6.4, 6.8, 5.7, 5.8, 6.4, 6.5, 7.7, 7.7, 6, 6.9, 5.6, 7.7, 6.3, 6.7, 7.2, 6.2, 6.1, 6.4, 7.2, 7.4, 7.9, 6.4, 6.3, 6.1, 7.7, 6.3, 6.4, 6, 6.9, 6.7, 6.9, 5.8, 6.8, 6.7, 6.7, 6.3, 6.5, 6.2, 5.9 ], "xaxis": "x", "y": [ 3.3, 2.7, 3, 2.9, 3, 3, 2.5, 2.9, 2.5, 3.6, 3.2, 2.7, 3, 2.5, 2.8, 3.2, 3, 3.8, 2.6, 2.2, 3.2, 2.8, 2.8, 2.7, 3.3, 3.2, 2.8, 3, 2.8, 3, 2.8, 3.8, 2.8, 2.8, 2.6, 3, 3.4, 3.1, 3, 3.1, 3.1, 3.1, 2.7, 3.2, 3.3, 3, 2.5, 3, 3.4, 3 ], "yaxis": "y" } ], "highlight": { "debounce": 0, "dynamic": false, "on": "plotly_click", "opacityDim": 0.2, "persistent": false, "selected": { "opacity": 1 }, "selectize": false }, "layout": { "annotations": [ { "ax": 0, "ay": 0, "font": { "color": "rgba(0,0,0,1)", "family": "", "size": 14.6119 }, "legendTitle": true, "showarrow": false, "text": "Species", "textangle": 0, "x": 1.02, "xanchor": "left", "xref": "paper", "y": 1, "yanchor": "bottom", "yref": "paper" } ], "barmode": "relative", "font": { "color": "rgba(0,0,0,1)", "family": "", "size": 14.6119 }, "hovermode": "closest", "legend": { "bgcolor": "rgba(255,255,255,1)", "bordercolor": "transparent", "borderwidth": 1.8898, "font": { "color": "rgba(0,0,0,1)", "family": "", "size": 11.6895 }, "y": 0.9381 }, "margin": { "b": 37.2603, "l": 43.105, "r": 7.3059, "t": 23.3059 }, "paper_bgcolor": "rgba(255,255,255,1)", "plot_bgcolor": "rgba(235,235,235,1)", "shapes": [ { "line": { "linetype": [], "width": 0 }, "type": "rect", "x0": 0, "x1": 1, "xref": "paper", "y0": 0, "y1": 1, "yref": "paper" } ], "showlegend": true, "xaxis": { "anchor": "y", "automargin": true, "autorange": false, "categoryarray": [ "5", "6", "7", "8" ], "categoryorder": "array", "domain": [ 0, 1 ], "gridcolor": "rgba(255,255,255,1)", "gridwidth": 0.6642, "hoverformat": ".2f", "linecolor": {}, "linewidth": 0, "nticks": {}, "range": [ 4.12, 8.08 ], "showgrid": true, "showline": false, "showticklabels": true, "tickangle": 0, "tickcolor": "rgba(51,51,51,1)", "tickfont": { "color": "rgba(77,77,77,1)", "family": "", "size": 11.6895 }, "ticklen": 3.653, "tickmode": "array", "ticks": "outside", "ticktext": [ "5", "6", "7", "8" ], "tickvals": [ 5, 6, 7, 8 ], "tickwidth": 0.6642, "title": { "font": { "color": "rgba(0,0,0,1)", "family": "", "size": 14.6119 }, "text": "Sepal.Length" }, "type": "linear", "zeroline": false }, "yaxis": { "anchor": "x", "automargin": true, "autorange": false, "categoryarray": [ "2.0", "2.5", "3.0", "3.5", "4.0", "4.5" ], "categoryorder": "array", "domain": [ 0, 1 ], "gridcolor": "rgba(255,255,255,1)", "gridwidth": 0.6642, "hoverformat": ".2f", "linecolor": {}, "linewidth": 0, "nticks": {}, "range": [ 1.88, 4.52 ], "showgrid": true, "showline": false, "showticklabels": true, "tickangle": 0, "tickcolor": "rgba(51,51,51,1)", "tickfont": { "color": "rgba(77,77,77,1)", "family": "", "size": 11.6895 }, "ticklen": 3.653, "tickmode": "array", "ticks": "outside", "ticktext": [ "2.0", "2.5", "3.0", "3.5", "4.0", "4.5" ], "tickvals": [ 2, 2.5, 3, 3.5, 4, 4.5 ], "tickwidth": 0.6642, "title": { "font": { "color": "rgba(0,0,0,1)", "family": "", "size": 14.6119 }, "text": "Sepal.Width" }, "type": "linear", "zeroline": false } }, "shinyEvents": [ "plotly_hover", "plotly_click", "plotly_selected", "plotly_relayout", "plotly_brushed", "plotly_brushing", "plotly_clickannotation", "plotly_doubleclick", "plotly_deselect", "plotly_afterplot", "plotly_sunburstclick" ], "source": "A", "visdat": { "d5c2f434d99": [ "function (y) ", "x" ] } }, "text/html": [ "\n", "\n", "\t\n", "\t\t\n", "\t\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\t\n", "\t\t
\n", "\n", "\t\n", "\n" ], "text/plain": [ "HTML widgets cannot be represented in plain text (need html)" ] }, "metadata": { "text/html": { "isolated": true } }, "output_type": "display_data" } ], "source": [ "iris %>%\n", " ggplot(aes(x = Sepal.Length, y = Sepal.Width, col = Species)) +\n", " geom_point(alpha = 0.8) -> figure\n", "ggplotly(figure)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Podstawowe wykresy" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Warning message:\n", "“`arrange_()` was deprecated in dplyr 0.7.0.\n", "Please use `arrange()` instead.\n", "See vignette('programming') for more help\n", "\u001b[90mThis warning is displayed once every 8 hours.\u001b[39m\n", "\u001b[90mCall `lifecycle::last_warnings()` to see where this warning was generated.\u001b[39m”\n" ] }, { "data": { "application/vnd.plotly.v1+json": { "attrs": { "d5c5ad1589f": { "alpha_stroke": 1, "color": {}, "hoverinfo": "text", "inherit": true, "mode": "markers", "sizes": [ 10, 100 ], "spans": [ 1, 20 ], "text": {}, "type": "scatter", "x": {}, "y": {} } }, "base_url": "https://plot.ly", "config": { "showSendToCloud": false }, "cur_data": "d5c5ad1589f", "data": [ { "error_x": { "color": "rgba(102,194,165,1)" }, "error_y": { "color": "rgba(102,194,165,1)" }, "hoverinfo": [ "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text" ], "line": { "color": "rgba(102,194,165,1)" }, "marker": { "color": "rgba(102,194,165,1)", "line": { "color": "rgba(102,194,165,1)" } }, "mode": "markers", "name": "1", "text": [ "Phenols: 2.8
Alcohol: 14.23", "Phenols: 2.65
Alcohol: 13.2", "Phenols: 2.8
Alcohol: 13.16", "Phenols: 3.85
Alcohol: 14.37", "Phenols: 2.8
Alcohol: 13.24", "Phenols: 3.27
Alcohol: 14.2", "Phenols: 2.5
Alcohol: 14.39", "Phenols: 2.6
Alcohol: 14.06", "Phenols: 2.8
Alcohol: 14.83", "Phenols: 2.98
Alcohol: 13.86", "Phenols: 2.95
Alcohol: 14.1", "Phenols: 2.2
Alcohol: 14.12", "Phenols: 2.6
Alcohol: 13.75", "Phenols: 3.1
Alcohol: 14.75", "Phenols: 3.3
Alcohol: 14.38", "Phenols: 2.85
Alcohol: 13.63", "Phenols: 2.8
Alcohol: 14.3", "Phenols: 2.95
Alcohol: 13.83", "Phenols: 3.3
Alcohol: 14.19", "Phenols: 2.7
Alcohol: 13.64", "Phenols: 3
Alcohol: 14.06", "Phenols: 2.41
Alcohol: 12.93", "Phenols: 2.61
Alcohol: 13.71", "Phenols: 2.48
Alcohol: 12.85", "Phenols: 2.53
Alcohol: 13.5", "Phenols: 2.63
Alcohol: 13.05", "Phenols: 2.85
Alcohol: 13.39", "Phenols: 2.4
Alcohol: 13.3", "Phenols: 2.95
Alcohol: 13.87", "Phenols: 2.65
Alcohol: 14.02", "Phenols: 3
Alcohol: 13.73", "Phenols: 2.86
Alcohol: 13.58", "Phenols: 2.42
Alcohol: 13.68", "Phenols: 2.95
Alcohol: 13.76", "Phenols: 2.35
Alcohol: 13.51", "Phenols: 2.7
Alcohol: 13.48", "Phenols: 2.6
Alcohol: 13.28", "Phenols: 2.45
Alcohol: 13.05", "Phenols: 2.4
Alcohol: 13.07", "Phenols: 3
Alcohol: 14.22", "Phenols: 3.15
Alcohol: 13.56", "Phenols: 2.45
Alcohol: 13.41", "Phenols: 3.25
Alcohol: 13.88", "Phenols: 2.64
Alcohol: 13.24", "Phenols: 3
Alcohol: 13.05", "Phenols: 2.85
Alcohol: 14.21", "Phenols: 3.25
Alcohol: 14.38", "Phenols: 3.1
Alcohol: 13.9", "Phenols: 2.75
Alcohol: 14.1", "Phenols: 2.88
Alcohol: 13.94", "Phenols: 2.72
Alcohol: 13.05", "Phenols: 2.45
Alcohol: 13.83", "Phenols: 3.88
Alcohol: 13.82", "Phenols: 3
Alcohol: 13.77", "Phenols: 2.6
Alcohol: 13.74", "Phenols: 2.96
Alcohol: 13.56", "Phenols: 3.2
Alcohol: 14.22", "Phenols: 3
Alcohol: 13.29", "Phenols: 3.4
Alcohol: 13.72" ], "textfont": { "color": "rgba(102,194,165,1)" }, "type": "scatter", "x": [ 2.8, 2.65, 2.8, 3.85, 2.8, 3.27, 2.5, 2.6, 2.8, 2.98, 2.95, 2.2, 2.6, 3.1, 3.3, 2.85, 2.8, 2.95, 3.3, 2.7, 3, 2.41, 2.61, 2.48, 2.53, 2.63, 2.85, 2.4, 2.95, 2.65, 3, 2.86, 2.42, 2.95, 2.35, 2.7, 2.6, 2.45, 2.4, 3, 3.15, 2.45, 3.25, 2.64, 3, 2.85, 3.25, 3.1, 2.75, 2.88, 2.72, 2.45, 3.88, 3, 2.6, 2.96, 3.2, 3, 3.4 ], "xaxis": "x", "y": [ 14.23, 13.2, 13.16, 14.37, 13.24, 14.2, 14.39, 14.06, 14.83, 13.86, 14.1, 14.12, 13.75, 14.75, 14.38, 13.63, 14.3, 13.83, 14.19, 13.64, 14.06, 12.93, 13.71, 12.85, 13.5, 13.05, 13.39, 13.3, 13.87, 14.02, 13.73, 13.58, 13.68, 13.76, 13.51, 13.48, 13.28, 13.05, 13.07, 14.22, 13.56, 13.41, 13.88, 13.24, 13.05, 14.21, 14.38, 13.9, 14.1, 13.94, 13.05, 13.83, 13.82, 13.77, 13.74, 13.56, 14.22, 13.29, 13.72 ], "yaxis": "y" }, { "error_x": { "color": "rgba(252,141,98,1)" }, "error_y": { "color": "rgba(252,141,98,1)" }, "hoverinfo": [ "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text" ], "line": { "color": "rgba(252,141,98,1)" }, "marker": { "color": "rgba(252,141,98,1)", "line": { "color": "rgba(252,141,98,1)" } }, "mode": "markers", "name": "2", "text": [ "Phenols: 1.98
Alcohol: 12.37", "Phenols: 2.05
Alcohol: 12.33", "Phenols: 2.02
Alcohol: 12.64", "Phenols: 2.1
Alcohol: 13.67", "Phenols: 3.5
Alcohol: 12.37", "Phenols: 1.89
Alcohol: 12.17", "Phenols: 2.42
Alcohol: 12.37", "Phenols: 2.98
Alcohol: 13.11", "Phenols: 2.11
Alcohol: 12.37", "Phenols: 2.53
Alcohol: 13.34", "Phenols: 1.85
Alcohol: 12.21", "Phenols: 1.1
Alcohol: 12.29", "Phenols: 2.95
Alcohol: 13.86", "Phenols: 1.88
Alcohol: 13.49", "Phenols: 3.3
Alcohol: 12.99", "Phenols: 3.38
Alcohol: 11.96", "Phenols: 1.61
Alcohol: 11.66", "Phenols: 1.95
Alcohol: 13.03", "Phenols: 1.72
Alcohol: 11.84", "Phenols: 1.9
Alcohol: 12.33", "Phenols: 2.83
Alcohol: 12.7", "Phenols: 2.42
Alcohol: 12", "Phenols: 2.2
Alcohol: 12.72", "Phenols: 2
Alcohol: 12.08", "Phenols: 1.65
Alcohol: 13.05", "Phenols: 2.2
Alcohol: 11.84", "Phenols: 2.2
Alcohol: 12.67", "Phenols: 1.78
Alcohol: 12.16", "Phenols: 1.92
Alcohol: 11.65", "Phenols: 1.95
Alcohol: 11.64", "Phenols: 2.2
Alcohol: 12.08", "Phenols: 1.6
Alcohol: 12.08", "Phenols: 1.45
Alcohol: 12", "Phenols: 1.38
Alcohol: 12.69", "Phenols: 2.45
Alcohol: 12.29", "Phenols: 3.02
Alcohol: 11.62", "Phenols: 2.5
Alcohol: 12.47", "Phenols: 1.6
Alcohol: 11.81", "Phenols: 2.55
Alcohol: 12.29", "Phenols: 3.52
Alcohol: 12.37", "Phenols: 2.85
Alcohol: 12.29", "Phenols: 2.23
Alcohol: 12.08", "Phenols: 1.45
Alcohol: 12.6", "Phenols: 2.56
Alcohol: 12.34", "Phenols: 2.5
Alcohol: 11.82", "Phenols: 2.2
Alcohol: 12.51", "Phenols: 1.68
Alcohol: 12.42", "Phenols: 1.65
Alcohol: 12.25", "Phenols: 1.38
Alcohol: 12.72", "Phenols: 2.36
Alcohol: 12.22", "Phenols: 2.74
Alcohol: 11.61", "Phenols: 3.18
Alcohol: 11.46", "Phenols: 2.55
Alcohol: 12.52", "Phenols: 1.75
Alcohol: 11.76", "Phenols: 2.48
Alcohol: 11.41", "Phenols: 2.56
Alcohol: 12.08", "Phenols: 2.46
Alcohol: 11.03", "Phenols: 1.98
Alcohol: 11.82", "Phenols: 2
Alcohol: 12.42", "Phenols: 1.63
Alcohol: 12.77", "Phenols: 2
Alcohol: 12", "Phenols: 2.9
Alcohol: 11.45", "Phenols: 3.18
Alcohol: 11.56", "Phenols: 2.2
Alcohol: 12.42", "Phenols: 2.62
Alcohol: 13.05", "Phenols: 2.86
Alcohol: 11.87", "Phenols: 2.6
Alcohol: 12.07", "Phenols: 2.74
Alcohol: 12.43", "Phenols: 2.13
Alcohol: 11.79", "Phenols: 2.22
Alcohol: 12.37", "Phenols: 2.1
Alcohol: 12.04" ], "textfont": { "color": "rgba(252,141,98,1)" }, "type": "scatter", "x": [ 1.98, 2.05, 2.02, 2.1, 3.5, 1.89, 2.42, 2.98, 2.11, 2.53, 1.85, 1.1, 2.95, 1.88, 3.3, 3.38, 1.61, 1.95, 1.72, 1.9, 2.83, 2.42, 2.2, 2, 1.65, 2.2, 2.2, 1.78, 1.92, 1.95, 2.2, 1.6, 1.45, 1.38, 2.45, 3.02, 2.5, 1.6, 2.55, 3.52, 2.85, 2.23, 1.45, 2.56, 2.5, 2.2, 1.68, 1.65, 1.38, 2.36, 2.74, 3.18, 2.55, 1.75, 2.48, 2.56, 2.46, 1.98, 2, 1.63, 2, 2.9, 3.18, 2.2, 2.62, 2.86, 2.6, 2.74, 2.13, 2.22, 2.1 ], "xaxis": "x", "y": [ 12.37, 12.33, 12.64, 13.67, 12.37, 12.17, 12.37, 13.11, 12.37, 13.34, 12.21, 12.29, 13.86, 13.49, 12.99, 11.96, 11.66, 13.03, 11.84, 12.33, 12.7, 12, 12.72, 12.08, 13.05, 11.84, 12.67, 12.16, 11.65, 11.64, 12.08, 12.08, 12, 12.69, 12.29, 11.62, 12.47, 11.81, 12.29, 12.37, 12.29, 12.08, 12.6, 12.34, 11.82, 12.51, 12.42, 12.25, 12.72, 12.22, 11.61, 11.46, 12.52, 11.76, 11.41, 12.08, 11.03, 11.82, 12.42, 12.77, 12, 11.45, 11.56, 12.42, 13.05, 11.87, 12.07, 12.43, 11.79, 12.37, 12.04 ], "yaxis": "y" }, { "error_x": { "color": "rgba(141,160,203,1)" }, "error_y": { "color": "rgba(141,160,203,1)" }, "hoverinfo": [ "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text" ], "line": { "color": "rgba(141,160,203,1)" }, "marker": { "color": "rgba(141,160,203,1)", "line": { "color": "rgba(141,160,203,1)" } }, "mode": "markers", "name": "3", "text": [ "Phenols: 1.51
Alcohol: 12.86", "Phenols: 1.3
Alcohol: 12.88", "Phenols: 1.15
Alcohol: 12.81", "Phenols: 1.7
Alcohol: 12.7", "Phenols: 2
Alcohol: 12.51", "Phenols: 1.62
Alcohol: 12.6", "Phenols: 1.38
Alcohol: 12.25", "Phenols: 1.79
Alcohol: 12.53", "Phenols: 1.62
Alcohol: 13.49", "Phenols: 2.32
Alcohol: 12.84", "Phenols: 1.54
Alcohol: 12.93", "Phenols: 1.4
Alcohol: 13.36", "Phenols: 1.55
Alcohol: 13.52", "Phenols: 2
Alcohol: 13.62", "Phenols: 1.38
Alcohol: 12.25", "Phenols: 1.5
Alcohol: 13.16", "Phenols: 0.98
Alcohol: 13.88", "Phenols: 1.7
Alcohol: 12.87", "Phenols: 1.93
Alcohol: 13.32", "Phenols: 1.41
Alcohol: 13.08", "Phenols: 1.4
Alcohol: 13.5", "Phenols: 1.48
Alcohol: 12.79", "Phenols: 2.2
Alcohol: 13.11", "Phenols: 1.8
Alcohol: 13.23", "Phenols: 1.48
Alcohol: 12.58", "Phenols: 1.74
Alcohol: 13.17", "Phenols: 1.8
Alcohol: 13.84", "Phenols: 1.9
Alcohol: 12.45", "Phenols: 2.8
Alcohol: 14.34", "Phenols: 2.6
Alcohol: 13.48", "Phenols: 2.3
Alcohol: 12.36", "Phenols: 1.83
Alcohol: 13.69", "Phenols: 1.65
Alcohol: 12.85", "Phenols: 1.39
Alcohol: 12.96", "Phenols: 1.35
Alcohol: 13.78", "Phenols: 1.28
Alcohol: 13.73", "Phenols: 1.7
Alcohol: 13.45", "Phenols: 1.48
Alcohol: 12.82", "Phenols: 1.55
Alcohol: 13.58", "Phenols: 1.98
Alcohol: 13.4", "Phenols: 1.25
Alcohol: 12.2", "Phenols: 1.39
Alcohol: 12.77", "Phenols: 1.68
Alcohol: 14.16", "Phenols: 1.68
Alcohol: 13.71", "Phenols: 1.8
Alcohol: 13.4", "Phenols: 1.59
Alcohol: 13.27", "Phenols: 1.65
Alcohol: 13.17", "Phenols: 2.05
Alcohol: 14.13" ], "textfont": { "color": "rgba(141,160,203,1)" }, "type": "scatter", "x": [ 1.51, 1.3, 1.15, 1.7, 2, 1.62, 1.38, 1.79, 1.62, 2.32, 1.54, 1.4, 1.55, 2, 1.38, 1.5, 0.98, 1.7, 1.93, 1.41, 1.4, 1.48, 2.2, 1.8, 1.48, 1.74, 1.8, 1.9, 2.8, 2.6, 2.3, 1.83, 1.65, 1.39, 1.35, 1.28, 1.7, 1.48, 1.55, 1.98, 1.25, 1.39, 1.68, 1.68, 1.8, 1.59, 1.65, 2.05 ], "xaxis": "x", "y": [ 12.86, 12.88, 12.81, 12.7, 12.51, 12.6, 12.25, 12.53, 13.49, 12.84, 12.93, 13.36, 13.52, 13.62, 12.25, 13.16, 13.88, 12.87, 13.32, 13.08, 13.5, 12.79, 13.11, 13.23, 12.58, 13.17, 13.84, 12.45, 14.34, 13.48, 12.36, 13.69, 12.85, 12.96, 13.78, 13.73, 13.45, 12.82, 13.58, 13.4, 12.2, 12.77, 14.16, 13.71, 13.4, 13.27, 13.17, 14.13 ], "yaxis": "y" } ], "highlight": { "debounce": 0, "dynamic": false, "on": "plotly_click", "opacityDim": 0.2, "persistent": false, "selected": { "opacity": 1 }, "selectize": false }, "layout": { "hovermode": "closest", "margin": { "b": 40, "l": 60, "r": 10, "t": 25 }, "showlegend": true, "xaxis": { "automargin": true, "domain": [ 0, 1 ], "title": "Phenols" }, "yaxis": { "automargin": true, "domain": [ 0, 1 ], "title": "Alcohol" } }, "shinyEvents": [ "plotly_hover", "plotly_click", "plotly_selected", "plotly_relayout", "plotly_brushed", "plotly_brushing", "plotly_clickannotation", "plotly_doubleclick", "plotly_deselect", "plotly_afterplot", "plotly_sunburstclick" ], "source": "A", "visdat": { "d5c5ad1589f": [ "function () ", "plotlyVisDat" ] } }, "text/html": [ "\n", "\n", "\t\n", "\t\t\n", "\t\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\t\n", "\t\t
\n", "\n", "\t\n", "\n" ], "text/plain": [ "HTML widgets cannot be represented in plain text (need html)" ] }, "metadata": { "text/html": { "isolated": true } }, "output_type": "display_data" } ], "source": [ "# Scatterplot\n", "rattle.data::wine %>% # data set\n", " plot_ly(x = ~Phenols, \n", " y = ~Alcohol, \n", " hoverinfo = 'text',\n", " text = ~paste('Phenols:', Phenols, '
Alcohol:', Alcohol)) %>% \n", " add_markers(color = ~Type) # add points" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "attrs": { "d5c4ad584f7": { "alpha_stroke": 1, "inherit": true, "sizes": [ 10, 100 ], "spans": [ 1, 20 ], "type": "bar", "x": {}, "y": {} } }, "base_url": "https://plot.ly", "config": { "showSendToCloud": false }, "cur_data": "d5c4ad584f7", "data": [ { "error_x": { "color": "rgba(31,119,180,1)" }, "error_y": { "color": "rgba(31,119,180,1)" }, "marker": { "color": "rgba(31,119,180,1)", "line": { "color": "rgba(31,119,180,1)" } }, "type": "bar", "x": [ "1", "2", "3" ], "xaxis": "x", "y": [ 59, 71, 48 ], "yaxis": "y" } ], "highlight": { "debounce": 0, "dynamic": false, "on": "plotly_click", "opacityDim": 0.2, "persistent": false, "selected": { "opacity": 1 }, "selectize": false }, "layout": { "hovermode": "closest", "margin": { "b": 40, "l": 60, "r": 10, "t": 25 }, "showlegend": false, "xaxis": { "automargin": true, "categoryarray": [ "1", "2", "3" ], "categoryorder": "array", "domain": [ 0, 1 ], "title": "Type", "type": "category" }, "yaxis": { "automargin": true, "domain": [ 0, 1 ], "title": "n" } }, "shinyEvents": [ "plotly_hover", "plotly_click", "plotly_selected", "plotly_relayout", "plotly_brushed", "plotly_brushing", "plotly_clickannotation", "plotly_doubleclick", "plotly_deselect", "plotly_afterplot", "plotly_sunburstclick" ], "source": "A", "visdat": { "d5c4ad584f7": [ "function () ", "plotlyVisDat" ] } }, "text/html": [ "\n", "\n", "\t\n", "\t\t\n", "\t\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\t\n", "\t\t
\n", "\n", "\t\n", "\n" ], "text/plain": [ "HTML widgets cannot be represented in plain text (need html)" ] }, "metadata": { "text/html": { "isolated": true } }, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "attrs": { "d5c22f4ba83": { "alpha_stroke": 1, "inherit": true, "sizes": [ 10, 100 ], "spans": [ 1, 20 ], "type": "bar", "x": {}, "y": {} } }, "base_url": "https://plot.ly", "config": { "showSendToCloud": false }, "cur_data": "d5c22f4ba83", "data": [ { "error_x": { "color": "rgba(31,119,180,1)" }, "error_y": { "color": "rgba(31,119,180,1)" }, "marker": { "color": "rgba(31,119,180,1)", "line": { "color": "rgba(31,119,180,1)" } }, "type": "bar", "x": [ "1", "2", "3" ], "xaxis": "x", "y": [ 59, 71, 48 ], "yaxis": "y" } ], "highlight": { "debounce": 0, "dynamic": false, "on": "plotly_click", "opacityDim": 0.2, "persistent": false, "selected": { "opacity": 1 }, "selectize": false }, "layout": { "hovermode": "closest", "margin": { "b": 40, "l": 60, "r": 10, "t": 25 }, "showlegend": false, "xaxis": { "automargin": true, "categoryarray": [ "2", "1", "3" ], "categoryorder": "array", "domain": [ 0, 1 ], "title": "Type", "type": "category" }, "yaxis": { "automargin": true, "domain": [ 0, 1 ], "title": "n" } }, "shinyEvents": [ "plotly_hover", "plotly_click", "plotly_selected", "plotly_relayout", "plotly_brushed", "plotly_brushing", "plotly_clickannotation", "plotly_doubleclick", "plotly_deselect", "plotly_afterplot", "plotly_sunburstclick" ], "source": "A", "visdat": { "d5c22f4ba83": [ "function () ", "plotlyVisDat" ] } }, "text/html": [ "\n", "\n", "\t\n", "\t\t\n", "\t\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\t\n", "\t\t
\n", "\n", "\t\n", "\n" ], "text/plain": [ "HTML widgets cannot be represented in plain text (need html)" ] }, "metadata": { "text/html": { "isolated": true } }, "output_type": "display_data" } ], "source": [ "# Barplot\n", "rattle.data::wine %>%\n", " count(Type) %>%\n", " plot_ly(x = ~Type, y = ~n) %>%\n", " add_bars()\n", "\n", "rattle.data::wine %>%\n", " count(Type) %>%\n", " mutate(Type = forcats::fct_reorder(Type, n, .desc = TRUE)) %>%\n", " plot_ly(x = ~Type, y = ~n) %>%\n", " add_bars()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "attrs": { "d5c7f3bd4aa": { "alpha_stroke": 1, "color": {}, "inherit": true, "sizes": [ 10, 100 ], "spans": [ 1, 20 ], "type": "bar", "x": {}, "y": {} } }, "base_url": "https://plot.ly", "config": { "showSendToCloud": false }, "cur_data": "d5c7f3bd4aa", "data": [ { "error_x": { "color": "rgba(102,194,165,1)" }, "error_y": { "color": "rgba(102,194,165,1)" }, "marker": { "color": "rgba(102,194,165,1)", "line": { "color": "rgba(102,194,165,1)" } }, "name": "1", "textfont": { "color": "rgba(102,194,165,1)" }, "type": "bar", "x": [ "Strong", "Weak" ], "xaxis": "x", "y": [ 57, 2 ], "yaxis": "y" }, { "error_x": { "color": "rgba(252,141,98,1)" }, "error_y": { "color": "rgba(252,141,98,1)" }, "marker": { "color": "rgba(252,141,98,1)", "line": { "color": "rgba(252,141,98,1)" } }, "name": "2", "textfont": { "color": "rgba(252,141,98,1)" }, "type": "bar", "x": [ "Strong", "Weak" ], "xaxis": "x", "y": [ 8, 63 ], "yaxis": "y" }, { "error_x": { "color": "rgba(141,160,203,1)" }, "error_y": { "color": "rgba(141,160,203,1)" }, "marker": { "color": "rgba(141,160,203,1)", "line": { "color": "rgba(141,160,203,1)" } }, "name": "3", "textfont": { "color": "rgba(141,160,203,1)" }, "type": "bar", "x": [ "Strong", "Weak" ], "xaxis": "x", "y": [ 27, 21 ], "yaxis": "y" } ], "highlight": { "debounce": 0, "dynamic": false, "on": "plotly_click", "opacityDim": 0.2, "persistent": false, "selected": { "opacity": 1 }, "selectize": false }, "layout": { "barmode": "stack", "hovermode": "closest", "margin": { "b": 40, "l": 60, "r": 10, "t": 25 }, "showlegend": true, "xaxis": { "automargin": true, "categoryarray": [ "Strong", "Weak" ], "categoryorder": "array", "domain": [ 0, 1 ], "title": "Power", "type": "category" }, "yaxis": { "automargin": true, "domain": [ 0, 1 ], "title": "n" } }, "shinyEvents": [ "plotly_hover", "plotly_click", "plotly_selected", "plotly_relayout", "plotly_brushed", "plotly_brushing", "plotly_clickannotation", "plotly_doubleclick", "plotly_deselect", "plotly_afterplot", "plotly_sunburstclick" ], "source": "A", "visdat": { "d5c7f3bd4aa": [ "function () ", "plotlyVisDat" ] } }, "text/html": [ "\n", "\n", "\t\n", "\t\t\n", "\t\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\t\n", "\t\t
\n", "\n", "\t\n", "\n" ], "text/plain": [ "HTML widgets cannot be represented in plain text (need html)" ] }, "metadata": { "text/html": { "isolated": true } }, "output_type": "display_data" } ], "source": [ "# Stacked barplot\n", "rattle.data::wine %>%\n", " mutate(Power = ifelse(Alcohol < 13, 'Weak', 'Strong')) %>%\n", " as_tibble() %>% \n", " count(Type, Power) %>% \n", " plot_ly(x = ~Power, y = ~n, color = ~Type) %>%\n", " add_bars() %>%\n", " layout(barmode = 'stack')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "attrs": { "d5c370ed341": { "alpha_stroke": 1, "color": "navy", "inherit": true, "nbinsx": 10, "opacity": 0.5, "sizes": [ 10, 100 ], "spans": [ 1, 20 ], "type": "histogram", "x": {} } }, "base_url": "https://plot.ly", "config": { "showSendToCloud": false }, "cur_data": "d5c370ed341", "data": [ { "error_x": { "color": "rgba(0,0,128,1)" }, "error_y": { "color": "rgba(0,0,128,1)" }, "marker": { "color": "rgba(0,0,128,1)", "line": { "color": "rgba(0,0,128,1)" } }, "nbinsx": 10, "opacity": 0.5, "type": "histogram", "x": [ 2.8, 2.65, 2.8, 3.85, 2.8, 3.27, 2.5, 2.6, 2.8, 2.98, 2.95, 2.2, 2.6, 3.1, 3.3, 2.85, 2.8, 2.95, 3.3, 2.7, 3, 2.41, 2.61, 2.48, 2.53, 2.63, 2.85, 2.4, 2.95, 2.65, 3, 2.86, 2.42, 2.95, 2.35, 2.7, 2.6, 2.45, 2.4, 3, 3.15, 2.45, 3.25, 2.64, 3, 2.85, 3.25, 3.1, 2.75, 2.88, 2.72, 2.45, 3.88, 3, 2.6, 2.96, 3.2, 3, 3.4, 1.98, 2.05, 2.02, 2.1, 3.5, 1.89, 2.42, 2.98, 2.11, 2.53, 1.85, 1.1, 2.95, 1.88, 3.3, 3.38, 1.61, 1.95, 1.72, 1.9, 2.83, 2.42, 2.2, 2, 1.65, 2.2, 2.2, 1.78, 1.92, 1.95, 2.2, 1.6, 1.45, 1.38, 2.45, 3.02, 2.5, 1.6, 2.55, 3.52, 2.85, 2.23, 1.45, 2.56, 2.5, 2.2, 1.68, 1.65, 1.38, 2.36, 2.74, 3.18, 2.55, 1.75, 2.48, 2.56, 2.46, 1.98, 2, 1.63, 2, 2.9, 3.18, 2.2, 2.62, 2.86, 2.6, 2.74, 2.13, 2.22, 2.1, 1.51, 1.3, 1.15, 1.7, 2, 1.62, 1.38, 1.79, 1.62, 2.32, 1.54, 1.4, 1.55, 2, 1.38, 1.5, 0.98, 1.7, 1.93, 1.41, 1.4, 1.48, 2.2, 1.8, 1.48, 1.74, 1.8, 1.9, 2.8, 2.6, 2.3, 1.83, 1.65, 1.39, 1.35, 1.28, 1.7, 1.48, 1.55, 1.98, 1.25, 1.39, 1.68, 1.68, 1.8, 1.59, 1.65, 2.05 ], "xaxis": "x", "yaxis": "y" } ], "highlight": { "debounce": 0, "dynamic": false, "on": "plotly_click", "opacityDim": 0.2, "persistent": false, "selected": { "opacity": 1 }, "selectize": false }, "layout": { "hovermode": "closest", "margin": { "b": 40, "l": 60, "r": 10, "t": 25 }, "showlegend": false, "xaxis": { "automargin": true, "domain": [ 0, 1 ], "title": "Phenols" }, "yaxis": { "automargin": true, "domain": [ 0, 1 ] } }, "shinyEvents": [ "plotly_hover", "plotly_click", "plotly_selected", "plotly_relayout", "plotly_brushed", "plotly_brushing", "plotly_clickannotation", "plotly_doubleclick", "plotly_deselect", "plotly_afterplot", "plotly_sunburstclick" ], "source": "A", "visdat": { "d5c370ed341": [ "function () ", "plotlyVisDat" ] } }, "text/html": [ "\n", "\n", "\t\n", "\t\t\n", "\t\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\t\n", "\t\t
\n", "\n", "\t\n", "\n" ], "text/plain": [ "HTML widgets cannot be represented in plain text (need html)" ] }, "metadata": { "text/html": { "isolated": true } }, "output_type": "display_data" } ], "source": [ "# Histogram\n", "rattle.data::wine %>%\n", " plot_ly(x = ~Phenols) %>% \n", " add_histogram(nbinsx = 10, color = I('navy'), opacity = 0.5)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "attrs": { "d5c2724096a": { "alpha_stroke": 1, "inherit": true, "sizes": [ 10, 100 ], "spans": [ 1, 20 ], "type": "box", "x": {}, "y": {} } }, "base_url": "https://plot.ly", "config": { "showSendToCloud": false }, "cur_data": "d5c2724096a", "data": [ { "fillcolor": "rgba(31,119,180,0.5)", "line": { "color": "rgba(31,119,180,1)" }, "marker": { "color": "rgba(31,119,180,1)", "line": { "color": "rgba(31,119,180,1)" } }, "type": "box", "x": [ "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3" ], "xaxis": "x", "y": [ 2.8, 2.65, 2.8, 3.85, 2.8, 3.27, 2.5, 2.6, 2.8, 2.98, 2.95, 2.2, 2.6, 3.1, 3.3, 2.85, 2.8, 2.95, 3.3, 2.7, 3, 2.41, 2.61, 2.48, 2.53, 2.63, 2.85, 2.4, 2.95, 2.65, 3, 2.86, 2.42, 2.95, 2.35, 2.7, 2.6, 2.45, 2.4, 3, 3.15, 2.45, 3.25, 2.64, 3, 2.85, 3.25, 3.1, 2.75, 2.88, 2.72, 2.45, 3.88, 3, 2.6, 2.96, 3.2, 3, 3.4, 1.98, 2.05, 2.02, 2.1, 3.5, 1.89, 2.42, 2.98, 2.11, 2.53, 1.85, 1.1, 2.95, 1.88, 3.3, 3.38, 1.61, 1.95, 1.72, 1.9, 2.83, 2.42, 2.2, 2, 1.65, 2.2, 2.2, 1.78, 1.92, 1.95, 2.2, 1.6, 1.45, 1.38, 2.45, 3.02, 2.5, 1.6, 2.55, 3.52, 2.85, 2.23, 1.45, 2.56, 2.5, 2.2, 1.68, 1.65, 1.38, 2.36, 2.74, 3.18, 2.55, 1.75, 2.48, 2.56, 2.46, 1.98, 2, 1.63, 2, 2.9, 3.18, 2.2, 2.62, 2.86, 2.6, 2.74, 2.13, 2.22, 2.1, 1.51, 1.3, 1.15, 1.7, 2, 1.62, 1.38, 1.79, 1.62, 2.32, 1.54, 1.4, 1.55, 2, 1.38, 1.5, 0.98, 1.7, 1.93, 1.41, 1.4, 1.48, 2.2, 1.8, 1.48, 1.74, 1.8, 1.9, 2.8, 2.6, 2.3, 1.83, 1.65, 1.39, 1.35, 1.28, 1.7, 1.48, 1.55, 1.98, 1.25, 1.39, 1.68, 1.68, 1.8, 1.59, 1.65, 2.05 ], "yaxis": "y" } ], "highlight": { "debounce": 0, "dynamic": false, "on": "plotly_click", "opacityDim": 0.2, "persistent": false, "selected": { "opacity": 1 }, "selectize": false }, "layout": { "hovermode": "closest", "margin": { "b": 40, "l": 60, "r": 10, "t": 25 }, "showlegend": false, "title": "Phenols and type of wine", "xaxis": { "automargin": true, "categoryarray": [ "1", "2", "3" ], "categoryorder": "array", "domain": [ 0, 1 ], "title": "Type of wine", "type": "category" }, "yaxis": { "automargin": true, "domain": [ 0, 1 ], "title": "Total phenols" } }, "shinyEvents": [ "plotly_hover", "plotly_click", "plotly_selected", "plotly_relayout", "plotly_brushed", "plotly_brushing", "plotly_clickannotation", "plotly_doubleclick", "plotly_deselect", "plotly_afterplot", "plotly_sunburstclick" ], "source": "A", "visdat": { "d5c2724096a": [ "function () ", "plotlyVisDat" ] } }, "text/html": [ "\n", "\n", "\t\n", "\t\t\n", "\t\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\t\n", "\t\t
\n", "\n", "\t\n", "\n" ], "text/plain": [ "HTML widgets cannot be represented in plain text (need html)" ] }, "metadata": { "text/html": { "isolated": true } }, "output_type": "display_data" } ], "source": [ "# Boxplot\n", "rattle.data::wine %>%\n", " plot_ly(y = ~Phenols, x = ~Type) %>%\n", " add_boxplot() %>% \n", " layout(xaxis = list(title = 'Type of wine'),\n", " yaxis = list(title = 'Total phenols'),\n", " title = 'Phenols and type of wine')" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "attrs": { "d5c5554bcf2": { "alpha_stroke": 1, "inherit": true, "mode": "markers", "showlegend": false, "sizes": [ 10, 100 ], "spans": [ 1, 20 ], "type": "scatter", "x": {}, "y": {} }, "d5c5554bcf2.1": { "alpha_stroke": 1, "inherit": true, "mode": "lines", "name": "LOESS", "sizes": [ 10, 100 ], "spans": [ 1, 20 ], "type": "scatter", "x": {}, "y": {} }, "d5c5554bcf2.2": { "alpha_stroke": 1, "inherit": true, "mode": "lines", "name": "LM", "sizes": [ 10, 100 ], "spans": [ 1, 20 ], "type": "scatter", "x": {}, "y": {} } }, "base_url": "https://plot.ly", "config": { "showSendToCloud": false }, "cur_data": "d5c5554bcf2", "data": [ { "error_x": { "color": "rgba(31,119,180,1)" }, "error_y": { "color": "rgba(31,119,180,1)" }, "line": { "color": "rgba(31,119,180,1)" }, "marker": { "color": "rgba(31,119,180,1)", "line": { "color": "rgba(31,119,180,1)" } }, "mode": "markers", "showlegend": false, "type": "scatter", "x": [ 3.06, 2.76, 3.24, 3.49, 2.69, 3.39, 2.52, 2.51, 2.98, 3.15, 3.32, 2.43, 2.76, 3.69, 3.64, 2.91, 3.14, 3.4, 3.93, 3.03, 3.17, 2.41, 2.88, 2.37, 2.61, 2.68, 2.94, 2.19, 2.97, 2.33, 3.25, 3.19, 2.69, 2.74, 2.53, 2.98, 2.68, 2.43, 2.64, 3.04, 3.29, 2.68, 3.56, 2.63, 3, 2.65, 3.17, 3.39, 2.92, 3.54, 3.27, 2.99, 3.74, 2.79, 2.9, 2.78, 3, 3.23, 3.67, 0.57, 1.09, 1.41, 1.79, 3.1, 1.75, 2.65, 3.18, 2, 1.3, 1.28, 1.02, 2.86, 1.84, 2.89, 2.14, 1.57, 2.03, 1.32, 1.85, 2.55, 2.26, 2.53, 1.58, 1.59, 2.21, 1.94, 1.69, 1.61, 1.69, 1.59, 1.5, 1.25, 1.46, 2.25, 2.26, 2.27, 0.99, 2.5, 3.75, 2.99, 2.17, 1.36, 2.11, 1.64, 1.92, 1.84, 2.03, 1.76, 2.04, 2.92, 2.58, 2.27, 2.03, 2.01, 2.29, 2.17, 1.6, 2.09, 1.25, 1.64, 2.79, 5.08, 2.13, 2.65, 3.03, 2.65, 3.15, 2.24, 2.45, 1.75, 1.25, 1.22, 1.09, 1.2, 0.58, 0.66, 0.47, 0.6, 0.48, 0.6, 0.5, 0.5, 0.52, 0.8, 0.78, 0.55, 0.34, 0.65, 0.76, 1.39, 1.57, 1.36, 1.28, 0.83, 0.58, 0.63, 0.83, 0.58, 1.31, 1.1, 0.92, 0.56, 0.6, 0.7, 0.68, 0.47, 0.92, 0.66, 0.84, 0.96, 0.49, 0.51, 0.7, 0.61, 0.75, 0.69, 0.68, 0.76 ], "xaxis": "x", "y": [ 14.23, 13.2, 13.16, 14.37, 13.24, 14.2, 14.39, 14.06, 14.83, 13.86, 14.1, 14.12, 13.75, 14.75, 14.38, 13.63, 14.3, 13.83, 14.19, 13.64, 14.06, 12.93, 13.71, 12.85, 13.5, 13.05, 13.39, 13.3, 13.87, 14.02, 13.73, 13.58, 13.68, 13.76, 13.51, 13.48, 13.28, 13.05, 13.07, 14.22, 13.56, 13.41, 13.88, 13.24, 13.05, 14.21, 14.38, 13.9, 14.1, 13.94, 13.05, 13.83, 13.82, 13.77, 13.74, 13.56, 14.22, 13.29, 13.72, 12.37, 12.33, 12.64, 13.67, 12.37, 12.17, 12.37, 13.11, 12.37, 13.34, 12.21, 12.29, 13.86, 13.49, 12.99, 11.96, 11.66, 13.03, 11.84, 12.33, 12.7, 12, 12.72, 12.08, 13.05, 11.84, 12.67, 12.16, 11.65, 11.64, 12.08, 12.08, 12, 12.69, 12.29, 11.62, 12.47, 11.81, 12.29, 12.37, 12.29, 12.08, 12.6, 12.34, 11.82, 12.51, 12.42, 12.25, 12.72, 12.22, 11.61, 11.46, 12.52, 11.76, 11.41, 12.08, 11.03, 11.82, 12.42, 12.77, 12, 11.45, 11.56, 12.42, 13.05, 11.87, 12.07, 12.43, 11.79, 12.37, 12.04, 12.86, 12.88, 12.81, 12.7, 12.51, 12.6, 12.25, 12.53, 13.49, 12.84, 12.93, 13.36, 13.52, 13.62, 12.25, 13.16, 13.88, 12.87, 13.32, 13.08, 13.5, 12.79, 13.11, 13.23, 12.58, 13.17, 13.84, 12.45, 14.34, 13.48, 12.36, 13.69, 12.85, 12.96, 13.78, 13.73, 13.45, 12.82, 13.58, 13.4, 12.2, 12.77, 14.16, 13.71, 13.4, 13.27, 13.17, 14.13 ], "yaxis": "y" }, { "error_x": { "color": "rgba(255,127,14,1)" }, "error_y": { "color": "rgba(255,127,14,1)" }, "line": { "color": "rgba(255,127,14,1)" }, "marker": { "color": "rgba(255,127,14,1)", "line": { "color": "rgba(255,127,14,1)" } }, "mode": "lines", "name": "LOESS", "type": "scatter", "x": [ 0.34, 0.47, 0.47, 0.48, 0.49, 0.5, 0.5, 0.51, 0.52, 0.55, 0.56, 0.57, 0.58, 0.58, 0.58, 0.6, 0.6, 0.6, 0.61, 0.63, 0.65, 0.66, 0.66, 0.68, 0.68, 0.69, 0.7, 0.7, 0.75, 0.76, 0.76, 0.78, 0.8, 0.83, 0.83, 0.84, 0.92, 0.92, 0.96, 0.99, 1.02, 1.09, 1.09, 1.1, 1.2, 1.22, 1.25, 1.25, 1.25, 1.28, 1.28, 1.3, 1.31, 1.32, 1.36, 1.36, 1.39, 1.41, 1.46, 1.5, 1.57, 1.57, 1.58, 1.59, 1.59, 1.6, 1.61, 1.64, 1.64, 1.69, 1.69, 1.75, 1.75, 1.76, 1.79, 1.84, 1.84, 1.85, 1.92, 1.94, 2, 2.01, 2.03, 2.03, 2.03, 2.04, 2.09, 2.11, 2.13, 2.14, 2.17, 2.17, 2.19, 2.21, 2.24, 2.25, 2.26, 2.26, 2.27, 2.27, 2.29, 2.33, 2.37, 2.41, 2.43, 2.43, 2.45, 2.5, 2.51, 2.52, 2.53, 2.53, 2.55, 2.58, 2.61, 2.63, 2.64, 2.65, 2.65, 2.65, 2.65, 2.68, 2.68, 2.68, 2.69, 2.69, 2.74, 2.76, 2.76, 2.78, 2.79, 2.79, 2.86, 2.88, 2.89, 2.9, 2.91, 2.92, 2.92, 2.94, 2.97, 2.98, 2.98, 2.99, 2.99, 3, 3, 3.03, 3.03, 3.04, 3.06, 3.1, 3.14, 3.15, 3.15, 3.17, 3.17, 3.18, 3.19, 3.23, 3.24, 3.25, 3.27, 3.29, 3.32, 3.39, 3.39, 3.4, 3.49, 3.54, 3.56, 3.64, 3.67, 3.69, 3.74, 3.75, 3.93, 5.08 ], "xaxis": "x", "y": [ 13.3267, 13.2212, 13.2212, 13.2133, 13.2055, 13.1977, 13.1977, 13.1899, 13.1821, 13.1587, 13.1509, 13.1431, 13.1353, 13.1353, 13.1353, 13.1197, 13.1197, 13.1197, 13.1118, 13.0961, 13.0802, 13.0722, 13.0722, 13.0562, 13.0562, 13.0482, 13.0401, 13.0401, 12.9999, 12.9918, 12.9918, 12.9758, 12.9597, 12.9358, 12.9358, 12.9279, 12.8653, 12.8653, 12.8348, 12.8124, 12.7905, 12.7415, 12.7415, 12.7348, 12.6718, 12.6596, 12.6396, 12.6396, 12.6396, 12.6179, 12.6179, 12.6028, 12.5951, 12.5873, 12.5556, 12.5556, 12.5317, 12.5159, 12.4781, 12.4505, 12.4112, 12.4112, 12.4067, 12.4027, 12.4027, 12.3989, 12.3956, 12.3866, 12.3866, 12.3743, 12.3743, 12.3641, 12.3641, 12.363, 12.3604, 12.3592, 12.3592, 12.3595, 12.3663, 12.3699, 12.3854, 12.3887, 12.3958, 12.3958, 12.3958, 12.3997, 12.4224, 12.433, 12.4445, 12.4508, 12.4731, 12.4731, 12.4906, 12.5099, 12.5419, 12.5533, 12.565, 12.565, 12.5769, 12.5769, 12.6016, 12.6532, 12.7066, 12.7599, 12.7861, 12.7861, 12.8117, 12.8717, 12.8828, 12.8935, 12.9039, 12.9039, 12.9248, 12.958, 12.9931, 13.0172, 13.0294, 13.0418, 13.0418, 13.0418, 13.0418, 13.0792, 13.0792, 13.0792, 13.0918, 13.0918, 13.1545, 13.1791, 13.1791, 13.2034, 13.2153, 13.2153, 13.2932, 13.3132, 13.3229, 13.3326, 13.3424, 13.3522, 13.3522, 13.372, 13.4016, 13.4115, 13.4115, 13.4213, 13.4213, 13.4312, 13.4312, 13.4605, 13.4605, 13.4702, 13.4893, 13.5269, 13.5629, 13.5716, 13.5716, 13.5887, 13.5887, 13.597, 13.605, 13.6353, 13.6423, 13.6492, 13.6622, 13.6744, 13.6913, 13.7235, 13.7235, 13.7273, 13.7526, 13.7599, 13.7614, 13.76, 13.7564, 13.7531, 13.7416, 13.7387, 13.6567, 11.9296 ], "yaxis": "y" }, { "error_x": { "color": "rgba(44,160,44,1)" }, "error_y": { "color": "rgba(44,160,44,1)" }, "line": { "color": "rgba(44,160,44,1)" }, "marker": { "color": "rgba(44,160,44,1)", "line": { "color": "rgba(44,160,44,1)" } }, "mode": "lines", "name": "LM", "type": "scatter", "x": [ 0.34, 0.47, 0.47, 0.48, 0.49, 0.5, 0.5, 0.51, 0.52, 0.55, 0.56, 0.57, 0.58, 0.58, 0.58, 0.6, 0.6, 0.6, 0.61, 0.63, 0.65, 0.66, 0.66, 0.68, 0.68, 0.69, 0.7, 0.7, 0.75, 0.76, 0.76, 0.78, 0.8, 0.83, 0.83, 0.84, 0.92, 0.92, 0.96, 0.99, 1.02, 1.09, 1.09, 1.1, 1.2, 1.22, 1.25, 1.25, 1.25, 1.28, 1.28, 1.3, 1.31, 1.32, 1.36, 1.36, 1.39, 1.41, 1.46, 1.5, 1.57, 1.57, 1.58, 1.59, 1.59, 1.6, 1.61, 1.64, 1.64, 1.69, 1.69, 1.75, 1.75, 1.76, 1.79, 1.84, 1.84, 1.85, 1.92, 1.94, 2, 2.01, 2.03, 2.03, 2.03, 2.04, 2.09, 2.11, 2.13, 2.14, 2.17, 2.17, 2.19, 2.21, 2.24, 2.25, 2.26, 2.26, 2.27, 2.27, 2.29, 2.33, 2.37, 2.41, 2.43, 2.43, 2.45, 2.5, 2.51, 2.52, 2.53, 2.53, 2.55, 2.58, 2.61, 2.63, 2.64, 2.65, 2.65, 2.65, 2.65, 2.68, 2.68, 2.68, 2.69, 2.69, 2.74, 2.76, 2.76, 2.78, 2.79, 2.79, 2.86, 2.88, 2.89, 2.9, 2.91, 2.92, 2.92, 2.94, 2.97, 2.98, 2.98, 2.99, 2.99, 3, 3, 3.03, 3.03, 3.04, 3.06, 3.1, 3.14, 3.15, 3.15, 3.17, 3.17, 3.18, 3.19, 3.23, 3.24, 3.25, 3.27, 3.29, 3.32, 3.39, 3.39, 3.4, 3.49, 3.54, 3.56, 3.64, 3.67, 3.69, 3.74, 3.75, 3.93, 5.08 ], "xaxis": "x", "y": [ 13.0266, 12.9731, 12.9731, 12.9693, 12.9654, 12.9617, 12.9617, 12.9579, 12.9542, 12.9433, 12.9398, 12.9362, 12.9328, 12.9328, 12.9328, 12.9259, 12.9259, 12.9259, 12.9225, 12.9159, 12.9094, 12.9062, 12.9062, 12.8999, 12.8999, 12.8968, 12.8938, 12.8938, 12.8791, 12.8763, 12.8763, 12.8708, 12.8654, 12.8576, 12.8576, 12.8551, 12.8362, 12.8362, 12.8276, 12.8216, 12.8159, 12.8039, 12.8039, 12.8023, 12.7887, 12.7864, 12.7833, 12.7833, 12.7833, 12.7804, 12.7804, 12.7787, 12.7779, 12.7772, 12.7745, 12.7745, 12.7729, 12.772, 12.7705, 12.7699, 12.7703, 12.7703, 12.7705, 12.7707, 12.7707, 12.771, 12.7713, 12.7725, 12.7725, 12.7751, 12.7751, 12.7796, 12.7796, 12.7804, 12.7833, 12.7887, 12.7887, 12.7899, 12.7993, 12.8024, 12.8123, 12.8141, 12.8178, 12.8178, 12.8178, 12.8197, 12.8297, 12.834, 12.8384, 12.8407, 12.8477, 12.8477, 12.8526, 12.8576, 12.8654, 12.8681, 12.8708, 12.8708, 12.8736, 12.8736, 12.8792, 12.8908, 12.9031, 12.9159, 12.9225, 12.9225, 12.9293, 12.9469, 12.9506, 12.9542, 12.958, 12.958, 12.9655, 12.977, 12.9889, 12.9971, 13.0012, 13.0053, 13.0053, 13.0053, 13.0053, 13.018, 13.018, 13.018, 13.0223, 13.0223, 13.0443, 13.0534, 13.0534, 13.0626, 13.0673, 13.0673, 13.101, 13.1109, 13.116, 13.121, 13.1262, 13.1313, 13.1313, 13.1417, 13.1576, 13.1629, 13.1629, 13.1684, 13.1684, 13.1738, 13.1738, 13.1903, 13.1903, 13.1959, 13.2072, 13.2302, 13.2538, 13.2598, 13.2598, 13.2719, 13.2719, 13.278, 13.2842, 13.3091, 13.3154, 13.3218, 13.3346, 13.3476, 13.3674, 13.4147, 13.4147, 13.4217, 13.4856, 13.5224, 13.5373, 13.5987, 13.6223, 13.6383, 13.6788, 13.687, 13.841, 15.1072 ], "yaxis": "y" } ], "highlight": { "debounce": 0, "dynamic": false, "on": "plotly_click", "opacityDim": 0.2, "persistent": false, "selected": { "opacity": 1 }, "selectize": false }, "layout": { "hovermode": "closest", "margin": { "b": 40, "l": 60, "r": 10, "t": 25 }, "showlegend": true, "xaxis": { "automargin": true, "domain": [ 0, 1 ], "title": "Flavanoids" }, "yaxis": { "automargin": true, "domain": [ 0, 1 ], "title": "Alcohol" } }, "shinyEvents": [ "plotly_hover", "plotly_click", "plotly_selected", "plotly_relayout", "plotly_brushed", "plotly_brushing", "plotly_clickannotation", "plotly_doubleclick", "plotly_deselect", "plotly_afterplot", "plotly_sunburstclick" ], "source": "A", "visdat": { "d5c5554bcf2": [ "function () ", "plotlyVisDat" ] } }, "text/html": [ "\n", "\n", "\t\n", "\t\t\n", "\t\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\t\n", "\t\t
\n", "\n", "\t\n", "\n" ], "text/plain": [ "HTML widgets cannot be represented in plain text (need html)" ] }, "metadata": { "text/html": { "isolated": true } }, "output_type": "display_data" } ], "source": [ "# Adding a smoother\n", "model.loess <- loess(Alcohol ~ Flavanoids, data = rattle.data::wine)\n", "model.lm <- lm(Alcohol ~ poly(Flavanoids, 2), data = rattle.data::wine)\n", "rattle.data::wine %>%\n", " plot_ly(x = ~Flavanoids, y = ~Alcohol) %>% \n", " add_markers(showlegend = FALSE) %>%\n", " add_lines(y = ~fitted(model.loess), name = 'LOESS') %>% \n", " add_lines(y = ~fitted(model.lm), name = 'LM')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Subplot" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "attrs": { "d5c145938e2": { "alpha_stroke": 1, "inherit": true, "mode": "markers", "name": {}, "sizes": [ 10, 100 ], "spans": [ 1, 20 ], "type": "scatter", "x": {}, "y": {} }, "d5c1bb149a2": { "alpha_stroke": 1, "inherit": true, "mode": "markers", "name": {}, "sizes": [ 10, 100 ], "spans": [ 1, 20 ], "type": "scatter", "x": {}, "y": {} }, "d5c6da587dd": { "alpha_stroke": 1, "inherit": true, "mode": "markers", "name": {}, "sizes": [ 10, 100 ], "spans": [ 1, 20 ], "type": "scatter", "x": {}, "y": {} } }, "base_url": "https://plot.ly", "config": { "showSendToCloud": false }, "data": [ { "error_x": { "color": "rgba(31,119,180,1)" }, "error_y": { "color": "rgba(31,119,180,1)" }, "line": { "color": "rgba(31,119,180,1)" }, "marker": { "color": "rgba(31,119,180,1)", "line": { "color": "rgba(31,119,180,1)" } }, "mode": "markers", "name": "1", "type": "scatter", "x": [ 3.06, 2.76, 3.24, 3.49, 2.69, 3.39, 2.52, 2.51, 2.98, 3.15, 3.32, 2.43, 2.76, 3.69, 3.64, 2.91, 3.14, 3.4, 3.93, 3.03, 3.17, 2.41, 2.88, 2.37, 2.61, 2.68, 2.94, 2.19, 2.97, 2.33, 3.25, 3.19, 2.69, 2.74, 2.53, 2.98, 2.68, 2.43, 2.64, 3.04, 3.29, 2.68, 3.56, 2.63, 3, 2.65, 3.17, 3.39, 2.92, 3.54, 3.27, 2.99, 3.74, 2.79, 2.9, 2.78, 3, 3.23, 3.67 ], "xaxis": "x", "y": [ 14.23, 13.2, 13.16, 14.37, 13.24, 14.2, 14.39, 14.06, 14.83, 13.86, 14.1, 14.12, 13.75, 14.75, 14.38, 13.63, 14.3, 13.83, 14.19, 13.64, 14.06, 12.93, 13.71, 12.85, 13.5, 13.05, 13.39, 13.3, 13.87, 14.02, 13.73, 13.58, 13.68, 13.76, 13.51, 13.48, 13.28, 13.05, 13.07, 14.22, 13.56, 13.41, 13.88, 13.24, 13.05, 14.21, 14.38, 13.9, 14.1, 13.94, 13.05, 13.83, 13.82, 13.77, 13.74, 13.56, 14.22, 13.29, 13.72 ], "yaxis": "y" }, { "error_x": { "color": "rgba(255,127,14,1)" }, "error_y": { "color": "rgba(255,127,14,1)" }, "line": { "color": "rgba(255,127,14,1)" }, "marker": { "color": "rgba(255,127,14,1)", "line": { "color": "rgba(255,127,14,1)" } }, "mode": "markers", "name": "2", "type": "scatter", "x": [ 0.57, 1.09, 1.41, 1.79, 3.1, 1.75, 2.65, 3.18, 2, 1.3, 1.28, 1.02, 2.86, 1.84, 2.89, 2.14, 1.57, 2.03, 1.32, 1.85, 2.55, 2.26, 2.53, 1.58, 1.59, 2.21, 1.94, 1.69, 1.61, 1.69, 1.59, 1.5, 1.25, 1.46, 2.25, 2.26, 2.27, 0.99, 2.5, 3.75, 2.99, 2.17, 1.36, 2.11, 1.64, 1.92, 1.84, 2.03, 1.76, 2.04, 2.92, 2.58, 2.27, 2.03, 2.01, 2.29, 2.17, 1.6, 2.09, 1.25, 1.64, 2.79, 5.08, 2.13, 2.65, 3.03, 2.65, 3.15, 2.24, 2.45, 1.75 ], "xaxis": "x2", "y": [ 12.37, 12.33, 12.64, 13.67, 12.37, 12.17, 12.37, 13.11, 12.37, 13.34, 12.21, 12.29, 13.86, 13.49, 12.99, 11.96, 11.66, 13.03, 11.84, 12.33, 12.7, 12, 12.72, 12.08, 13.05, 11.84, 12.67, 12.16, 11.65, 11.64, 12.08, 12.08, 12, 12.69, 12.29, 11.62, 12.47, 11.81, 12.29, 12.37, 12.29, 12.08, 12.6, 12.34, 11.82, 12.51, 12.42, 12.25, 12.72, 12.22, 11.61, 11.46, 12.52, 11.76, 11.41, 12.08, 11.03, 11.82, 12.42, 12.77, 12, 11.45, 11.56, 12.42, 13.05, 11.87, 12.07, 12.43, 11.79, 12.37, 12.04 ], "yaxis": "y" }, { "error_x": { "color": "rgba(44,160,44,1)" }, "error_y": { "color": "rgba(44,160,44,1)" }, "line": { "color": "rgba(44,160,44,1)" }, "marker": { "color": "rgba(44,160,44,1)", "line": { "color": "rgba(44,160,44,1)" } }, "mode": "markers", "name": "3", "type": "scatter", "x": [ 1.25, 1.22, 1.09, 1.2, 0.58, 0.66, 0.47, 0.6, 0.48, 0.6, 0.5, 0.5, 0.52, 0.8, 0.78, 0.55, 0.34, 0.65, 0.76, 1.39, 1.57, 1.36, 1.28, 0.83, 0.58, 0.63, 0.83, 0.58, 1.31, 1.1, 0.92, 0.56, 0.6, 0.7, 0.68, 0.47, 0.92, 0.66, 0.84, 0.96, 0.49, 0.51, 0.7, 0.61, 0.75, 0.69, 0.68, 0.76 ], "xaxis": "x3", "y": [ 12.86, 12.88, 12.81, 12.7, 12.51, 12.6, 12.25, 12.53, 13.49, 12.84, 12.93, 13.36, 13.52, 13.62, 12.25, 13.16, 13.88, 12.87, 13.32, 13.08, 13.5, 12.79, 13.11, 13.23, 12.58, 13.17, 13.84, 12.45, 14.34, 13.48, 12.36, 13.69, 12.85, 12.96, 13.78, 13.73, 13.45, 12.82, 13.58, 13.4, 12.2, 12.77, 14.16, 13.71, 13.4, 13.27, 13.17, 14.13 ], "yaxis": "y" } ], "highlight": { "debounce": 0, "dynamic": false, "on": "plotly_click", "opacityDim": 0.2, "persistent": false, "selected": { "opacity": 1 }, "selectize": false }, "layout": { "annotations": [], "hovermode": "closest", "images": [], "margin": { "b": 40, "l": 60, "r": 10, "t": 25 }, "shapes": [], "showlegend": true, "xaxis": { "anchor": "y", "automargin": true, "domain": [ 0, 0.3133 ] }, "xaxis2": { "anchor": "y", "automargin": true, "domain": [ 0.3533, 0.6467 ] }, "xaxis3": { "anchor": "y", "automargin": true, "domain": [ 0.6867, 1 ] }, "yaxis": { "anchor": "x", "automargin": true, "domain": [ 0, 1 ], "title": "Alcohol" } }, "shinyEvents": [ "plotly_hover", "plotly_click", "plotly_selected", "plotly_relayout", "plotly_brushed", "plotly_brushing", "plotly_clickannotation", "plotly_doubleclick", "plotly_deselect", "plotly_afterplot", "plotly_sunburstclick" ], "source": "A", "subplot": true }, "text/html": [ "\n", "\n", "\t\n", "\t\t\n", "\t\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\t\n", "\t\t
\n", "\n", "\t\n", "\n" ], "text/plain": [ "HTML widgets cannot be represented in plain text (need html)" ] }, "metadata": { "text/html": { "isolated": true } }, "output_type": "display_data" } ], "source": [ "# Subplot\n", "rattle.data::wine %>% \n", " group_by(Type) %>% \n", " do(plot = plot_ly(data = ., x = ~Flavanoids, y = ~Alcohol) %>% \n", " add_markers(name = ~Type)) %>% \n", " subplot(nrows = 1, shareY = TRUE)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Customizing the plot" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "scrolled": true }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "attrs": { "d5c45ec6ea7": { "alpha_stroke": 1, "color": {}, "inherit": true, "mode": "markers", "sizes": [ 10, 100 ], "spans": [ 1, 20 ], "type": "scatter", "x": {}, "y": {} } }, "base_url": "https://plot.ly", "config": { "showSendToCloud": false }, "cur_data": "d5c45ec6ea7", "data": [ { "error_x": { "color": "rgba(102,194,165,1)" }, "error_y": { "color": "rgba(102,194,165,1)" }, "line": { "color": "rgba(102,194,165,1)" }, "marker": { "color": "rgba(102,194,165,1)", "line": { "color": "rgba(102,194,165,1)" } }, "mode": "markers", "name": "1", "textfont": { "color": "rgba(102,194,165,1)" }, "type": "scatter", "x": [ 2.8, 2.65, 2.8, 3.85, 2.8, 3.27, 2.5, 2.6, 2.8, 2.98, 2.95, 2.2, 2.6, 3.1, 3.3, 2.85, 2.8, 2.95, 3.3, 2.7, 3, 2.41, 2.61, 2.48, 2.53, 2.63, 2.85, 2.4, 2.95, 2.65, 3, 2.86, 2.42, 2.95, 2.35, 2.7, 2.6, 2.45, 2.4, 3, 3.15, 2.45, 3.25, 2.64, 3, 2.85, 3.25, 3.1, 2.75, 2.88, 2.72, 2.45, 3.88, 3, 2.6, 2.96, 3.2, 3, 3.4 ], "xaxis": "x", "y": [ 14.23, 13.2, 13.16, 14.37, 13.24, 14.2, 14.39, 14.06, 14.83, 13.86, 14.1, 14.12, 13.75, 14.75, 14.38, 13.63, 14.3, 13.83, 14.19, 13.64, 14.06, 12.93, 13.71, 12.85, 13.5, 13.05, 13.39, 13.3, 13.87, 14.02, 13.73, 13.58, 13.68, 13.76, 13.51, 13.48, 13.28, 13.05, 13.07, 14.22, 13.56, 13.41, 13.88, 13.24, 13.05, 14.21, 14.38, 13.9, 14.1, 13.94, 13.05, 13.83, 13.82, 13.77, 13.74, 13.56, 14.22, 13.29, 13.72 ], "yaxis": "y" }, { "error_x": { "color": "rgba(252,141,98,1)" }, "error_y": { "color": "rgba(252,141,98,1)" }, "line": { "color": "rgba(252,141,98,1)" }, "marker": { "color": "rgba(252,141,98,1)", "line": { "color": "rgba(252,141,98,1)" } }, "mode": "markers", "name": "2", "textfont": { "color": "rgba(252,141,98,1)" }, "type": "scatter", "x": [ 1.98, 2.05, 2.02, 2.1, 3.5, 1.89, 2.42, 2.98, 2.11, 2.53, 1.85, 1.1, 2.95, 1.88, 3.3, 3.38, 1.61, 1.95, 1.72, 1.9, 2.83, 2.42, 2.2, 2, 1.65, 2.2, 2.2, 1.78, 1.92, 1.95, 2.2, 1.6, 1.45, 1.38, 2.45, 3.02, 2.5, 1.6, 2.55, 3.52, 2.85, 2.23, 1.45, 2.56, 2.5, 2.2, 1.68, 1.65, 1.38, 2.36, 2.74, 3.18, 2.55, 1.75, 2.48, 2.56, 2.46, 1.98, 2, 1.63, 2, 2.9, 3.18, 2.2, 2.62, 2.86, 2.6, 2.74, 2.13, 2.22, 2.1 ], "xaxis": "x", "y": [ 12.37, 12.33, 12.64, 13.67, 12.37, 12.17, 12.37, 13.11, 12.37, 13.34, 12.21, 12.29, 13.86, 13.49, 12.99, 11.96, 11.66, 13.03, 11.84, 12.33, 12.7, 12, 12.72, 12.08, 13.05, 11.84, 12.67, 12.16, 11.65, 11.64, 12.08, 12.08, 12, 12.69, 12.29, 11.62, 12.47, 11.81, 12.29, 12.37, 12.29, 12.08, 12.6, 12.34, 11.82, 12.51, 12.42, 12.25, 12.72, 12.22, 11.61, 11.46, 12.52, 11.76, 11.41, 12.08, 11.03, 11.82, 12.42, 12.77, 12, 11.45, 11.56, 12.42, 13.05, 11.87, 12.07, 12.43, 11.79, 12.37, 12.04 ], "yaxis": "y" }, { "error_x": { "color": "rgba(141,160,203,1)" }, "error_y": { "color": "rgba(141,160,203,1)" }, "line": { "color": "rgba(141,160,203,1)" }, "marker": { "color": "rgba(141,160,203,1)", "line": { "color": "rgba(141,160,203,1)" } }, "mode": "markers", "name": "3", "textfont": { "color": "rgba(141,160,203,1)" }, "type": "scatter", "x": [ 1.51, 1.3, 1.15, 1.7, 2, 1.62, 1.38, 1.79, 1.62, 2.32, 1.54, 1.4, 1.55, 2, 1.38, 1.5, 0.98, 1.7, 1.93, 1.41, 1.4, 1.48, 2.2, 1.8, 1.48, 1.74, 1.8, 1.9, 2.8, 2.6, 2.3, 1.83, 1.65, 1.39, 1.35, 1.28, 1.7, 1.48, 1.55, 1.98, 1.25, 1.39, 1.68, 1.68, 1.8, 1.59, 1.65, 2.05 ], "xaxis": "x", "y": [ 12.86, 12.88, 12.81, 12.7, 12.51, 12.6, 12.25, 12.53, 13.49, 12.84, 12.93, 13.36, 13.52, 13.62, 12.25, 13.16, 13.88, 12.87, 13.32, 13.08, 13.5, 12.79, 13.11, 13.23, 12.58, 13.17, 13.84, 12.45, 14.34, 13.48, 12.36, 13.69, 12.85, 12.96, 13.78, 13.73, 13.45, 12.82, 13.58, 13.4, 12.2, 12.77, 14.16, 13.71, 13.4, 13.27, 13.17, 14.13 ], "yaxis": "y" } ], "highlight": { "debounce": 0, "dynamic": false, "on": "plotly_click", "opacityDim": 0.2, "persistent": false, "selected": { "opacity": 1 }, "selectize": false }, "layout": { "hovermode": "closest", "margin": { "b": 40, "l": 60, "r": 10, "t": 25 }, "paper_bgcolor": "#ebebeb", "showlegend": true, "title": "Alcohol and Phenols", "xaxis": { "automargin": true, "domain": [ 0, 1 ], "showgrid": false, "title": "Alcohol", "zeroline": false }, "yaxis": { "automargin": true, "domain": [ 0, 1 ], "showgrid": false, "title": "Total phenols", "zeroline": false } }, "shinyEvents": [ "plotly_hover", "plotly_click", "plotly_selected", "plotly_relayout", "plotly_brushed", "plotly_brushing", "plotly_clickannotation", "plotly_doubleclick", "plotly_deselect", "plotly_afterplot", "plotly_sunburstclick" ], "source": "A", "visdat": { "d5c45ec6ea7": [ "function () ", "plotlyVisDat" ] } }, "text/html": [ "\n", "\n", "\t\n", "\t\t\n", "\t\t\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\t\n", "\t\n", "\t\t
\n", "\n", "\t\n", "\n" ], "text/plain": [ "HTML widgets cannot be represented in plain text (need html)" ] }, "metadata": { "text/html": { "isolated": true } }, "output_type": "display_data" } ], "source": [ "# Customizing the plot\n", "rattle.data::wine %>% \n", " plot_ly(x = ~Phenols, \n", " y = ~Alcohol) %>% \n", " add_markers(color = ~Type) %>% \n", " layout(xaxis = list(title = 'Alcohol', showgrid = FALSE, zeroline = FALSE),\n", " yaxis = list(title = 'Total phenols', showgrid = FALSE, zeroline = FALSE),\n", " title = 'Alcohol and Phenols',\n", " paper_bgcolor = '#ebebeb')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Zadania" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Narysuj wykres przebiegu dla zbioru danych *LakeHuron*.\n", "2. Dla cech *Petal.Length* i *Petal.Width* ze zbioru danych *iris* narysuj wykres rozrzutu.\n", "3. Narysuj taki sam wykres jak w zadaniu poprzednim. Tym razem jednak, każdy gatunek irysa ma mieć swój kolor. Po najechaniu na punkt powinna wyświetlić się informacja o współrzędnych punktu oraz jego przynależności klasowej.\n", "4. Dla zbioru danych *esoph* wykonaj wykres słupkowy dla cechy *agegp*. \n", "5. Dla zbioru danych *volcano* narysuj wykres typu „mapa ciepła”.\n", "6. Niech dane będą wartości: 0,12, 0,3, 0,26, 0,16, 0,04, 0,12. Narysuj dla niech wykres kołowy z otworem w środku.\n", "7. Narysuj wykres pokazujący histogramy wszystkich cech numerycznych ze zbioru *iris*. Powinny się na nim zatem znaleźć 4 histogramy rozmieszczone w dwóch wierszach i dwóch kolumnach." ] } ], "metadata": { "kernelspec": { "display_name": "R", "language": "R", "name": "ir" }, "language_info": { "codemirror_mode": "r", "file_extension": ".r", "mimetype": "text/x-r-source", "name": "R", "pygments_lexer": "r", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 4 }