-
Notifications
You must be signed in to change notification settings - Fork 14
/
ggplot2-07-pozicija.Rmd
136 lines (101 loc) · 3.02 KB
/
ggplot2-07-pozicija.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---
title: "Sistemos ggplot2 pagrindai"
subtitle: "Pozicijos korekcijos"
output: html_notebook
editor_options:
chunk_output_type: inline
---
```{r setup}
library(tidyverse)
knitr::opts_chunk$set(fig.height = 3, fig.width = 6)
Sys.setlocale(locale = "Lithuanian")
```
Pozicijos korekcijos
=============================================================================
color vs. fill
-----------------------------------------------------------------------------
```{r}
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, color = cut))
```
```{r}
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = cut))
```
Du kategoriniai kintamieji
-----------------------------------------------------------------------------
```{r}
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = clarity))
```
position = "identity"
-----------------------------------------------------------------------------
```{r}
ggplot(data = diamonds, mapping = aes(x = cut, fill = clarity)) +
geom_bar(alpha = 1/5, position = "identity")
```
```{r}
ggplot(data = diamonds, mapping = aes(x = cut, colour = clarity)) +
geom_bar(fill = NA, position = "identity")
```
position = "fill"
-----------------------------------------------------------------------------
```{r}
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = clarity), position = "fill")
```
position = "dodge"
-----------------------------------------------------------------------------
```{r}
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = clarity), position = "dodge")
```
position = "jitter"
-----------------------------------------------------------------------------
Be `"jitter"`
```{r}
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy))
```
Su `"jitter"`
```{r}
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy), position = "jitter")
```
geom_point(position = "jitter") vs. geom_jitter()
-----------------------------------------------------------------------------
```{r}
ggplot(data = mpg) +
geom_jitter(mapping = aes(x = displ, y = hwy))
```
Daugiau informacijos
-----------------------------------------------------------------------------
```{r}
?position_dodge
```
```{r}
?position_fill
```
```{r}
?position_identity
```
```{r}
?position_jitter
```
```{r}
?position_stack
```
Užduotys: pozicijos korekcijos
-----------------------------------------------------------------------------
1. Kaip galėtumėte patobulinti šitą grafiką, kad jis suteiktų daugiau informacijos (naudokite pozicijos korekcijas)?
```{r}
ggplot(data = mpg, mapping = aes(x = cty, y = hwy)) +
geom_point()
```
2. Kokie funkcijos `geom_jitter()` parametrai kontroliuoja taškų sklaidymo stiprumą?
3. Palyginkite funkcijas `geom_count()` ir `geom_jitter()`. Kuo jos panašios ir kuo skiriasi?
4. Kokią pagrindinę pozicijos korekciją naudoja funkcija `geom_boxplot()`. Pademonstruokite tai vizualizuodami duomenų lentelės `mpg` kintamuosius.
```{r}
ggplot(mpg) +
geom_boxplot(___)
```