-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_2b_interactive.Rmd
More file actions
116 lines (77 loc) · 2.24 KB
/
session_2b_interactive.Rmd
File metadata and controls
116 lines (77 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
title: "session_2a"
author: "Joe DeCesaro"
date: "8/3/2021"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(palmerpenguins)
```
### Plot a function in `ggplot2`
```{r}
eq <- function(x) {
3 * x ^ 2 + 4
}
# Use stat_function()
ggplot(data = data.frame(x = c(1, 100)), aes(x = x)) +
stat_function(fun = eq)
```
### Task
Plot $f(x)=2.4-5x^3+2.1x^2$
Over a range from -50 to +50
```{r}
eq_2 <- function(x) {
2.4 - (5 * x ^ 3) + (2.1 * x ^ 2)
}
ggplot(data = data.frame(x = c(-50, 50)), aes(x = x)) +
stat_function(fun = eq_2)
```
### `penguins` body mass and flipper lengths
Basic ggplot scatterplot of body mass (y) and flipper length (x)
```{r}
ggplot(data = penguins, aes(x = flipper_length_mm, y = body_mass_g)) +
geom_point(aes(color = species)) +
scale_color_manual(values = c("red", "purple", "cyan")) +
labs(x = "Flipper length (mm)",
y = " Body Mass (g)",
title = "Palmer Penguins size measurements",
caption = "Data collected by KB Gorman et al. at Palmer Station",
color = "species")
```
The 'missing' data sets mentioned by the console are just letting us know that we have two penguins where 1 or both data points that are being called are missing or incomplete.
### `penguins` body mass and flipper lengths now seperated by island and another theme
Basic ggplot scatterplot of body mass (y) and flipper length (x)
```{r}
ggplot(data = penguins, aes(x = flipper_length_mm, y = body_mass_g)) +
geom_point(aes(color = species)) +
scale_color_manual(values = c("red", "purple", "cyan")) +
labs(x = "Flipper length (mm)",
y = " Body Mass (g)",
title = "Palmer Penguins size measurements",
caption = "Data collected by KB Gorman et al. at Palmer Station",
color = "species") +
facet_wrap(~island) +
theme_grey()
```
### Higher Order Derivative
```{r}
gt <- expression(2.2 + 3.1 * t - 5.6 * t ^ 4)
dg_dt <- D(expr = gt, name = 't')
dg_dt
```
```{r}
d2g_dt2 <- D(expr = dg_dt, 't')
d2g_dt2
```
### Partial Derivatives
```{r}
f_xyz <- expression(2*x*y - 3*(x^2)*(z^3))
df_dx <- D(expr = f_xyz, 'x')
df_dx
df_dy <- D(expr = f_xyz, 'y')
df_dy
df_dz <- D(expr = f_xyz, 'z')
df_dz
```