From 242332bfebb6d4eb633128f958315b33dcd3d5f2 Mon Sep 17 00:00:00 2001 From: Halmaris Date: Wed, 28 Apr 2021 15:38:01 +0200 Subject: [PATCH] Fix for Lab 3 --- 03.ipynb | 544 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 490 insertions(+), 54 deletions(-) diff --git a/03.ipynb b/03.ipynb index 35ff2b9..f1d8680 100644 --- a/03.ipynb +++ b/03.ipynb @@ -117,13 +117,15 @@ { "cell_type": "code", "execution_count": 3, - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "attrs": { - "d5c2f434d99": { + "e682271a50ff": { "colour": {}, "type": "scatter", "x": {}, @@ -135,7 +137,7 @@ "doubleClick": "reset", "showSendToCloud": false }, - "cur_data": "d5c2f434d99", + "cur_data": "e682271a50ff", "data": [ { "hoverinfo": "text", @@ -893,7 +895,7 @@ ], "source": "A", "visdat": { - "d5c2f434d99": [ + "e682271a50ff": [ "function (y) ", "x" ] @@ -914,8 +916,8 @@ "\n", "\t\n", "\t\n", - "\t\t
\n", - "\n", + "\t\t
\n", + "\n", "\t\n", "\n" ], @@ -966,7 +968,7 @@ "data": { "application/vnd.plotly.v1+json": { "attrs": { - "d5c5ad1589f": { + "e68229139d1d": { "alpha_stroke": 1, "color": {}, "hoverinfo": "text", @@ -990,7 +992,7 @@ "config": { "showSendToCloud": false }, - "cur_data": "d5c5ad1589f", + "cur_data": "e68229139d1d", "data": [ { "error_x": { @@ -1856,7 +1858,7 @@ ], "source": "A", "visdat": { - "d5c5ad1589f": [ + "e68229139d1d": [ "function () ", "plotlyVisDat" ] @@ -1877,8 +1879,8 @@ "\n", "\t\n", "\t\n", - "\t\t
\n", - "\n", + "\t\t
\n", + "\n", "\t\n", "\n" ], @@ -1913,7 +1915,7 @@ "data": { "application/vnd.plotly.v1+json": { "attrs": { - "d5c4ad584f7": { + "e6824d87f900": { "alpha_stroke": 1, "inherit": true, "sizes": [ @@ -1933,7 +1935,7 @@ "config": { "showSendToCloud": false }, - "cur_data": "d5c4ad584f7", + "cur_data": "e6824d87f900", "data": [ { "error_x": { @@ -2022,7 +2024,7 @@ ], "source": "A", "visdat": { - "d5c4ad584f7": [ + "e6824d87f900": [ "function () ", "plotlyVisDat" ] @@ -2043,8 +2045,8 @@ "\n", "\t\n", "\t\n", - "\t\t
\n", - "\n", + "\t\t
\n", + "\n", "\t\n", "\n" ], @@ -2063,7 +2065,7 @@ "data": { "application/vnd.plotly.v1+json": { "attrs": { - "d5c22f4ba83": { + "e6827460e057": { "alpha_stroke": 1, "inherit": true, "sizes": [ @@ -2083,7 +2085,7 @@ "config": { "showSendToCloud": false }, - "cur_data": "d5c22f4ba83", + "cur_data": "e6827460e057", "data": [ { "error_x": { @@ -2172,7 +2174,7 @@ ], "source": "A", "visdat": { - "d5c22f4ba83": [ + "e6827460e057": [ "function () ", "plotlyVisDat" ] @@ -2193,8 +2195,8 @@ "\n", "\t\n", "\t\n", - "\t\t
\n", - "\n", + "\t\t
\n", + "\n", "\t\n", "\n" ], @@ -2233,7 +2235,7 @@ "data": { "application/vnd.plotly.v1+json": { "attrs": { - "d5c7f3bd4aa": { + "e6825d2021cd": { "alpha_stroke": 1, "color": {}, "inherit": true, @@ -2254,7 +2256,7 @@ "config": { "showSendToCloud": false }, - "cur_data": "d5c7f3bd4aa", + "cur_data": "e6825d2021cd", "data": [ { "error_x": { @@ -2403,7 +2405,7 @@ ], "source": "A", "visdat": { - "d5c7f3bd4aa": [ + "e6825d2021cd": [ "function () ", "plotlyVisDat" ] @@ -2424,8 +2426,8 @@ "\n", "\t\n", "\t\n", - "\t\t
\n", - "\n", + "\t\t
\n", + "\n", "\t\n", "\n" ], @@ -2461,7 +2463,7 @@ "data": { "application/vnd.plotly.v1+json": { "attrs": { - "d5c370ed341": { + "e6824b256193": { "alpha_stroke": 1, "color": "navy", "inherit": true, @@ -2483,7 +2485,7 @@ "config": { "showSendToCloud": false }, - "cur_data": "d5c370ed341", + "cur_data": "e6824b256193", "data": [ { "error_x": { @@ -2736,7 +2738,7 @@ ], "source": "A", "visdat": { - "d5c370ed341": [ + "e6824b256193": [ "function () ", "plotlyVisDat" ] @@ -2757,8 +2759,8 @@ "\n", "\t\n", "\t\n", - "\t\t
\n", - "\n", + "\t\t
\n", + "\n", "\t\n", "\n" ], @@ -2790,7 +2792,7 @@ "data": { "application/vnd.plotly.v1+json": { "attrs": { - "d5c2724096a": { + "e6822901b5c": { "alpha_stroke": 1, "inherit": true, "sizes": [ @@ -2810,7 +2812,7 @@ "config": { "showSendToCloud": false }, - "cur_data": "d5c2724096a", + "cur_data": "e6822901b5c", "data": [ { "fillcolor": "rgba(31,119,180,0.5)", @@ -3248,7 +3250,7 @@ ], "source": "A", "visdat": { - "d5c2724096a": [ + "e6822901b5c": [ "function () ", "plotlyVisDat" ] @@ -3269,8 +3271,8 @@ "\n", "\t\n", "\t\n", - "\t\t
\n", - "\n", + "\t\t
\n", + "\n", "\t\n", "\n" ], @@ -3305,7 +3307,7 @@ "data": { "application/vnd.plotly.v1+json": { "attrs": { - "d5c5554bcf2": { + "e68275cd1338": { "alpha_stroke": 1, "inherit": true, "mode": "markers", @@ -3322,7 +3324,7 @@ "x": {}, "y": {} }, - "d5c5554bcf2.1": { + "e68275cd1338.1": { "alpha_stroke": 1, "inherit": true, "mode": "lines", @@ -3339,7 +3341,7 @@ "x": {}, "y": {} }, - "d5c5554bcf2.2": { + "e68275cd1338.2": { "alpha_stroke": 1, "inherit": true, "mode": "lines", @@ -3361,7 +3363,7 @@ "config": { "showSendToCloud": false }, - "cur_data": "d5c5554bcf2", + "cur_data": "e68275cd1338", "data": [ { "error_x": { @@ -4562,7 +4564,7 @@ ], "source": "A", "visdat": { - "d5c5554bcf2": [ + "e68275cd1338": [ "function () ", "plotlyVisDat" ] @@ -4583,8 +4585,8 @@ "\n", "\t\n", "\t\n", - "\t\t
\n", - "\n", + "\t\t
\n", + "\n", "\t\n", "\n" ], @@ -4627,7 +4629,7 @@ "data": { "application/vnd.plotly.v1+json": { "attrs": { - "d5c145938e2": { + "e68213936778": { "alpha_stroke": 1, "inherit": true, "mode": "markers", @@ -4644,7 +4646,7 @@ "x": {}, "y": {} }, - "d5c1bb149a2": { + "e68275832f87": { "alpha_stroke": 1, "inherit": true, "mode": "markers", @@ -4661,7 +4663,7 @@ "x": {}, "y": {} }, - "d5c6da587dd": { + "e68277a58456": { "alpha_stroke": 1, "inherit": true, "mode": "markers", @@ -5207,8 +5209,8 @@ "\n", "\t\n", "\t\n", - "\t\t
\n", - "\n", + "\t\t
\n", + "\n", "\t\n", "\n" ], @@ -5244,14 +5246,14 @@ "cell_type": "code", "execution_count": 11, "metadata": { - "scrolled": true + "scrolled": false }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "attrs": { - "d5c45ec6ea7": { + "e6825d1a6c15": { "alpha_stroke": 1, "color": {}, "inherit": true, @@ -5273,7 +5275,7 @@ "config": { "showSendToCloud": false }, - "cur_data": "d5c45ec6ea7", + "cur_data": "e6825d1a6c15", "data": [ { "error_x": { @@ -5777,7 +5779,7 @@ ], "source": "A", "visdat": { - "d5c45ec6ea7": [ + "e6825d1a6c15": [ "function () ", "plotlyVisDat" ] @@ -5798,8 +5800,8 @@ "\n", "\t\n", "\t\n", - "\t\t
\n", - "\n", + "\t\t
\n", + "\n", "\t\n", "\n" ], @@ -5827,6 +5829,440 @@ " paper_bgcolor = '#ebebeb')" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Biblioteka highcharter" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Jest to wrapper dla biblioteki *Highcharts*. *Highcharts* () jest biblioteką do tworzenia wykresów napisaną w języku JavaScript, wydaną po raz pierwszy w 2009 roku. Jest bezpłatna do użytku osobistego / niekomercyjnego i płatna w przypadku zastosowań komercyjnych." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Warning message:\n", + "“package ‘highcharter’ was built under R version 3.6.2”\n", + "Registered S3 method overwritten by 'quantmod':\n", + " method from\n", + " as.zoo.data.frame zoo \n", + "\n" + ] + } + ], + "source": [ + "library(highcharter)\n", + "library(dplyr)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Parsed with column specification:\n", + "cols(\n", + " name = \u001b[31mcol_character()\u001b[39m,\n", + " sport = \u001b[31mcol_character()\u001b[39m,\n", + " nationality = \u001b[31mcol_character()\u001b[39m,\n", + " sex = \u001b[31mcol_character()\u001b[39m,\n", + " date_of_birth = \u001b[31mcol_character()\u001b[39m,\n", + " age = \u001b[32mcol_double()\u001b[39m,\n", + " height = \u001b[32mcol_double()\u001b[39m,\n", + " weight = \u001b[32mcol_double()\u001b[39m\n", + ")\n", + "\n" + ] + } + ], + "source": [ + "readr::read_csv('https://raw.githubusercontent.com/mekhatria/demo_highcharts/master/Olympics2012CapitalLetter.csv') %>% \n", + " select(-nationality, -date_of_birth, -name, -age) %>% \n", + " filter(sport %in% c('Gymnastics', 'Canoe', 'Hockey', 'Modern Pentathlon'), \n", + " sex == 'male') -> df" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Warning message:\n", + "“'hcboxplot' is deprecated.\n", + "Use 'data_to_boxplot' instead.\n", + "See help(\"Deprecated\")”\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + "\n", + "\t\n", + "\t\t\n", + "\t\t\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\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": [ + "hcboxplot(x = df$height,\n", + " var = df$sport,\n", + " name = 'Length',\n", + " outliers = FALSE) %>%\n", + " hc_title(text = 'Male height by discipline (Olympic 2012)') %>%\n", + " hc_yAxis(title = list(text = 'Height in metre')) %>%\n", + " hc_chart(type = 'column') %>% \n", + " hc_add_series(data = df,\n", + " type = 'scatter',\n", + " hcaes(x = 'sport', y = 'height', group = 'sport')) %>%\n", + " hc_plotOptions(scatter = list(\n", + " color = 'red',\n", + " marker = list(radius = 2,\n", + " symbol = 'circle',\n", + " lineWidth = 1))) %>%\n", + " hc_plotOptions(scatter = list(jitter = list(x = .1, y = 0)))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Biblioteka morrisjs" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Jest to inna biblioteka do tworzenia wykresów interaktywnych. Umożliwia tworzenie następujących wykresów:\n", + "1. Wykres liniowy (w czasie)\n", + "3. Wykres powierzchniowy (w czasie)\n", + "2. Wykres słupkowy (w czasie)\n", + "4. Wykres kołowy" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Loading required package: zoo\n", + "\n", + "\n", + "Attaching package: ‘zoo’\n", + "\n", + "\n", + "The following objects are masked from ‘package:base’:\n", + "\n", + " as.Date, as.Date.numeric\n", + "\n", + "\n" + ] + } + ], + "source": [ + "# devtools::install_github(\"tutuchan/morrisjs\") # Instalacja\n", + "library(morrisjs)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\t\n", + "\t\t\n", + "\t\t\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": [ + "morrisjs(ldeaths) %>% \n", + " mjsLine()" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\t\n", + "\t\t\n", + "\t\t\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": [ + "morrisjs(ts.union(fdeaths, mdeaths)) %>% \n", + " mjsLine()" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\t\n", + "\t\t\n", + "\t\t\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": [ + "morrisjs(ldeaths) %>% \n", + " mjsArea()" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\t\n", + "\t\t\n", + "\t\t\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": [ + "morrisjs(ldeaths) %>% \n", + " mjsBar()" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\t\n", + "\t\t\n", + "\t\t\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": [ + "morrisjs(list(labels = c('Africa', \n", + " 'Asia',\n", + " 'Europe',\n", + " 'North America',\n", + " 'South America'), \n", + " values = rbinom(5, 20, 0.5))) %>% \n", + " mjsDonut(options(colors = c('#66c2ff', '#ff66ff', \n", + " '#80ffd4', '#b3b3cc',\n", + " '#ffff80')))" + ] + }, { "cell_type": "markdown", "metadata": {}, -- 2.20.1