Cleared outputs, set some init cells
[ou-jupyter-r-demo.git] / 3dplot.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "# 3d plots of regression surfaces"
8 ]
9 },
10 {
11 "cell_type": "markdown",
12 "metadata": {
13 "heading_collapsed": true
14 },
15 "source": [
16 "### Initialisation"
17 ]
18 },
19 {
20 "cell_type": "code",
21 "execution_count": null,
22 "metadata": {
23 "hidden": true,
24 "init_cell": true
25 },
26 "outputs": [],
27 "source": [
28 "library(tidyverse)\n",
29 "# library(cowplot)\n",
30 "library(repr)\n",
31 "library(ggfortify)\n",
32 "\n",
33 "# Change plot size to 4 x 3\n",
34 "options(repr.plot.width=6, repr.plot.height=4)"
35 ]
36 },
37 {
38 "cell_type": "code",
39 "execution_count": null,
40 "metadata": {
41 "hidden": true,
42 "init_cell": true
43 },
44 "outputs": [],
45 "source": [
46 "source('plot_extensions.R')"
47 ]
48 },
49 {
50 "cell_type": "code",
51 "execution_count": null,
52 "metadata": {
53 "hidden": true,
54 "init_cell": true
55 },
56 "outputs": [],
57 "source": [
58 "library(scatterplot3d)"
59 ]
60 },
61 {
62 "cell_type": "markdown",
63 "metadata": {},
64 "source": [
65 "## Show plots"
66 ]
67 },
68 {
69 "cell_type": "code",
70 "execution_count": null,
71 "metadata": {},
72 "outputs": [],
73 "source": [
74 "rubber <- read.csv('rubber.csv')"
75 ]
76 },
77 {
78 "cell_type": "code",
79 "execution_count": null,
80 "metadata": {},
81 "outputs": [],
82 "source": [
83 "fit.hs <- lm(loss ~ hardness + strength, data = rubber)"
84 ]
85 },
86 {
87 "cell_type": "code",
88 "execution_count": null,
89 "metadata": {},
90 "outputs": [],
91 "source": [
92 "s3d <- scatterplot3d(x = rubber$hardness, y = rubber$strength, z = rubber$loss,\n",
93 " xlab = 'Hardness', ylab = \"Strength\", zlab = \"Loss\",\n",
94 " angle = 55, \n",
95 " type='h')\n",
96 "s3d$plane3d(fit.hs, draw_polygon = TRUE)"
97 ]
98 },
99 {
100 "cell_type": "code",
101 "execution_count": null,
102 "metadata": {},
103 "outputs": [],
104 "source": [
105 "anaerobic <- read.csv('anaerob.csv')\n",
106 "anaerobic$oxy2 <- anaerobic$oxygen^2"
107 ]
108 },
109 {
110 "cell_type": "code",
111 "execution_count": null,
112 "metadata": {},
113 "outputs": [],
114 "source": [
115 "anaerobic.n <- data.frame(scale(anaerobic))\n",
116 "head(anaerobic.n)"
117 ]
118 },
119 {
120 "cell_type": "code",
121 "execution_count": null,
122 "metadata": {},
123 "outputs": [],
124 "source": [
125 "fit.o2 <- lm(ventil ~ oxygen + oxy2, data = anaerobic.n)"
126 ]
127 },
128 {
129 "cell_type": "code",
130 "execution_count": null,
131 "metadata": {},
132 "outputs": [],
133 "source": [
134 "s3d <- with(anaerobic.n, scatterplot3d(x = oxygen, y = oxy2, z = ventil,\n",
135 " xlab = 'Oxygen', ylab = \"Oxygen2\", zlab = \"Ventil\",\n",
136 " angle = 205, \n",
137 " type='h'))\n",
138 "s3d$plane3d(fit.o2, draw_polygon = TRUE)"
139 ]
140 },
141 {
142 "cell_type": "code",
143 "execution_count": null,
144 "metadata": {},
145 "outputs": [],
146 "source": []
147 }
148 ],
149 "metadata": {
150 "kernelspec": {
151 "display_name": "R",
152 "language": "R",
153 "name": "ir"
154 },
155 "language_info": {
156 "codemirror_mode": "r",
157 "file_extension": ".r",
158 "mimetype": "text/x-r-source",
159 "name": "R",
160 "pygments_lexer": "r",
161 "version": "3.4.2"
162 }
163 },
164 "nbformat": 4,
165 "nbformat_minor": 2
166 }