forked from dgrtwo/data-screencasts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
us-wind.Rmd
130 lines (104 loc) · 2.73 KB
/
us-wind.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
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(tidyverse)
us_wind <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2018-11-06/us_wind.csv")
```
Look at the continental US (48 states, District of Columbia)
```{r}
us_wind_processed <- us_wind %>%
filter(!t_state %in% c("AK", "HI", "GU", "PR")) %>%
mutate(t_cap = ifelse(t_cap < 0, NA, t_cap)) %>%
mutate_if(is.numeric, ~ ifelse(. == -9999, NA, .))
wind_projects <- us_wind_processed %>%
group_by(p_name, t_state) %>%
summarize(year = min(p_year, na.rm = TRUE),
turbines = n(),
total_capacity = sum(t_cap),
lon = mean(xlong),
lat = mean(ylat),
lon_sd = sd(xlong),
lat_sd = sd(ylat)) %>%
ungroup()
```
How has turbine capacity changed over time?
```{r}
turbine_models <- us_wind_processed %>%
group_by(t_model) %>%
summarize(t_cap = median(t_cap),
t_hh = median(t_hh),
t_rd = median(t_rd),
t_rsa = median(t_rsa),
t_ttlh = median(t_ttlh),
turbines = n(),
projects = n_distinct(p_name)) %>%
arrange(desc(projects))
turbine_models %>%
ggplot(aes(t_ttlh, t_cap)) +
geom_point() +
labs(title = "When it comes to turbines, bigger is better!",
x = "Turbine total height (meters)",
y = "Turbine capacity (kW)")
turbine_models %>%
ggplot(aes(t_rsa, t_cap)) +
geom_point() +
labs(title = "When it comes to turbines, bigger is better!",
x = "Turbine rotor swept area (meters ^ 2)",
y = "Turbine capacity (kW)")
```
```{r}
wind_projects %>%
ggplot(aes(year, total_capacity)) +
geom_point()
wind_projects %>%
ggplot(aes(year, total_capacity / turbines)) +
geom_point()
```
```{r}
wind_projects %>%
ggplot(aes(lon, lat, size = turbines, color = year)) +
borders("state") +
geom_point() +
coord_map() +
theme_void()
```
### Animation
```{r}
library(gganimate)
ggplot(mtcars, aes(factor(cyl), mpg)) +
geom_boxplot() +
# Here comes the gganimate code
transition_states(
gear,
transition_length = 2,
state_length = 1
) +
enter_fade() +
exit_shrink() +
ease_aes('sine-in-out')
```
```{r}
wind_projects
wind_projects %>%
filter(!is.na(year), !is.infinite(year)) %>%
crossing(time = 1981:2018) %>%
filter(year <= time) %>%
ggplot(aes(lon, lat, size = turbines, color = year)) +
borders("state") +
geom_point() +
transition_manual(time) +
scale_color_continuous(guide = FALSE) +
labs(title = "Locations of wind turbine projects in continental US (1981-2018)") +
coord_map() +
theme_void()
p
anim_save("turbines.gif")
```
```{r}
us_wind_processed
```