forked from core-methods-in-edm/class-activity-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-activity-3.Rmd
74 lines (58 loc) · 1.61 KB
/
class-activity-3.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
---
title: "class activity 3"
author: Maho Hayashi
date: "10/1/2019"
output: html_document
---
#Mapping aesthetic to data to = layer
```{r}
#install.packages("ggplot2")
library(ggplot2)
ggplot(diamonds, aes(x = price, y = carat)) +
geom_point()
```
#Two layers
```{r}
ggplot(mpg, aes(reorder(class, hwy), hwy)) +
geom_jitter() +
geom_boxplot()
```
```{r}
#Plot count
ggplot(diamonds, aes(depth)) +
geom_histogram(aes(y = ..count..), binwidth=0.2) +
facet_wrap(~ cut) + xlim(50, 70)
#Plot density
ggplot(diamonds, aes(depth)) +
geom_histogram(aes(y = ..density..), binwidth=0.2) +
facet_wrap(~ cut) + xlim(50, 70)
```
```{r}
ggplot(mpg, aes(displ, hwy, color = class)) +
geom_point()
```
Can you create a line graph using the "economics_long" data set that shows change over time in "value01" for different categories of "variable"?
```{r}
economics_long
ggplot (economics_long, aes(date,value01, color = variable))+
geom_line()
```
If you would like to recreate the Minard graphic of Napoleon's Troops the code is below and the data is in this repo.
```{r}
cities <-read.table("cities.txt", header=TRUE)
temps <-read.table("temps.txt", header=TRUE)
troops <-read.table("troops.txt", header=TRUE)
ggplot(cities, aes(long, lat)) +
geom_path(aes(size = survivors, colour =
direction,
group = interaction(group, direction)), data =
troops) +
geom_text(aes(label = city), hjust = 0, vjust = 1,
size = 4)
# Polish appearance
last_plot() +
scale_x_continuous("long", limits = c(24, 39)) +
scale_y_continuous("lat") +
scale_colour_manual(values = c("grey50","red")) +
scale_size(range = c(1, 10))
```