-
Notifications
You must be signed in to change notification settings - Fork 1
/
ggplot-notebook.Rmd
134 lines (51 loc) · 1.27 KB
/
ggplot-notebook.Rmd
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
---
title: "ggplot2 Notebook"
output: html_notebook
---
# ggplot library
```{r}
library(tidyverse)
library(ggThemeAssist)
```
```{r plot 1}
ggplot(data= mpg) +
geom_point( aes(x= displ, y=hwy))
```
```{r plot 2}
ggplot(data= mpg) +
geom_point( aes(x= displ, y=hwy, color= class))
```
```{r plot 3}
ggplot(data= mpg) +
geom_point( aes(x= displ, y=hwy, size= class), color= "orange")
```
```{r plot 4}
ggplot(data= mpg) +
geom_bar( aes(x= class), fill='red')
```
```{r plot 5}
ggplot(mpg) +
geom_histogram( aes(x= hwy),
binwidth = 5,
fill="gold",
color='black') +
scale_x_continuous(breaks = seq(0,45,5), limits = c(0,50), expand = c(0,0))+
scale_y_continuous(breaks = seq(0,90,10), limits = c(0,90), expand = c(0,0))
# scale the data
```
```{r plot 6}
ggplot(mpg) +
geom_boxplot( aes(x= class, y=cty, fill=class))
```
```{r plot 7}
ggplot(mpg) +
geom_bar( aes(x= class, fill= factor(cyl))) +
labs(title = "cylinders by class", fill="cylinders") +
coord_flip()
```
```{r plot 8}
ggplot(mpg) +
geom_bar( aes(x= class, fill= factor(cyl)), position = 'dodge') +
labs(title = "cylinders by class", fill="cylinders") +
coord_flip()
```