-
Notifications
You must be signed in to change notification settings - Fork 0
/
TidyTues_29_Astro.Rmd
71 lines (56 loc) · 2.32 KB
/
TidyTues_29_Astro.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
# Astronauts
### Load Libraries
```{r}
library(tidyverse)
library(ggthemes)
library(grid)
```
### Import data
```{r}
astronauts <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-07-14/astronauts.csv')
```
### Max mission duration every year
```{r}
# # # Cleaning # # #
durations <- astronauts %>%
select(year_of_mission, hours_mission, mission_title, ascend_shuttle) %>%
group_by(year_of_mission) %>%
mutate(avg_mission_duration = mean(hours_mission)) %>%
filter(hours_mission == max(hours_mission)) %>%
ungroup() %>%
unique() %>%
arrange(year_of_mission)
# identify repeated data
durations %>%
count(year_of_mission) %>%
filter(n > 1)
durations$ascend_shuttle <- str_replace(durations$ascend_shuttle, "Soyuz TMA-9", "Soyuz TMA9")
# remove repeated data
durations_unique <- durations %>%
distinct(year_of_mission, .keep_all = TRUE) %>%
distinct(ascend_shuttle, .keep_all = TRUE)
# Graph #
space_theme <- theme_pander() +
theme(
panel.background = element_rect(fill = "gray10"),
panel.grid = element_line(color = "black"),
plot.title = element_text(vjust = -11, hjust = 0.03, color = "#ebcb00", size = 22),
plot.subtitle = element_text(vjust = -18, hjust = 0.03, color = "#ebcb00", size = 14, face = "italic"),
plot.background = element_rect(fill = "gray10"),
plot.caption = element_text(color = "white"),
axis.text = element_text(color = "white"),
axis.title.x = element_text(color = "white"),
axis.title.y = element_text(color = "white")
)
my_grob <- grid.text("average mission duration", x = 0.83, y = 0.194, gp=gpar(col="#b39e19", fontsize=9, fontface="italic"))
my_grob_2 <- grid.text("Valery Polyakov (launching on Soyuz TM-18)", x = 0.683, y = 0.96, gp=gpar(col="white", fontsize=9, fontface="italic"))
durations_unique %>%
ggplot(aes(year_of_mission, hours_mission)) +
geom_point(color = "#fffce8", shape = 8, size = 0.4) +
geom_smooth(aes(x = year_of_mission, y = avg_mission_duration), se = FALSE, color = "#b39e19", linetype = "dashed", size = 1/2) +
xlab("Year") +
ylab("Duration (hours)") +
labs(title = "The longest space missions", face = "bold", subtitle = "by year (1961 - 2019)", caption = "Graphic: @elidom5 | Data: Mariya Stavnichuk and Tatsuya Corlett") +
annotation_custom(my_grob) +
annotation_custom(my_grob_2) +
space_theme