forked from NSF-ALL-SPICE-Alliance/CS201
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcars_analysis.qmd
More file actions
74 lines (57 loc) · 1.11 KB
/
cars_analysis.qmd
File metadata and controls
74 lines (57 loc) · 1.11 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
---
title: "Cars Analysis"
format: html
editor: visual
---
#### Load in Libraries
```{r}
library(tidyverse)
library(plotly)
library(ggpubr)
```
#### Read in Dataset
```{r}
mtcars <- datasets::mtcars
```
```{r}
?mtcars
```
Lets examine the relationship between weight and mpg
```{r}
cars_wt_mpg <- ggplot(mtcars, aes(x = mpg, y = wt)) +
geom_point()
cars_wt_mpg
```
```{r}
ggplotly(cars_wt_mpg)
```
```{r}
mtcars <- mtcars %>%
tibble::rownames_to_column("model")
```
```{r}
cars_wt_mpg <- ggplot(mtcars, aes(x = mpg, y = wt, label = model, color = hp)) +
geom_point() +
geom_smooth() +
stat_cor()
cars_wt_mpg
```
```{r}
ggplotly(cars_wt_mpg)
```
```{r}
mtcars_split <- mtcars %>%
separate(model, into = c("make", "model"), sep = " ", extra = "merge")
```
### Challenge
What is the average mpg for each car manufacturer.
Please plot the results.
```{r}
average_manufacturer_mpg <- mtcars_split %>%
group_by(make) %>%
summarise(avg_mpg = mean(mpg), na.rm = TRUE)
```
```{r}
ggplot(average_manufacturer_mpg, aes(y = reorder(make, avg_mpg), x = avg_mpg, fill = avg_mpg)) +
geom_bar(stat = "identity")
```